This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn closest-integer-sqrt [x] | |
(-> x Math/sqrt Math/floor int)) | |
(defn prime-candidates-above-3 [x] | |
(lazy-seq (list* (dec (* 6 x)) (inc (* 6 x)) (prime-candidates-above-3 (inc x))))) | |
(def prime-candidates | |
(lazy-seq (list* 2 3 (prime-candidates-above-3 1)))) | |
(def none (comp not some)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn take-while-adjacent | |
[f coll] | |
(lazy-seq | |
(when-let [s (seq coll)] | |
(if (f (first s) (second s)) | |
(cons (first s) (take-while-adjacent f (rest s))) | |
(cons (first s) nil))))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns game-of-life.core | |
(:require [game-of-life.utils :refer [sum-of-vectors | |
setify]])) | |
(def neighbor-offsets | |
(into (hash-set) | |
(for [i (range -1 2) | |
j (range -1 2) | |
:when (not= [i j] [0 0])] | |
[i j]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn foo [x y] | |
`(intern *ns* ~x ~y)) | |
(defmacro def-symbols-across-range | |
[[from step] & symbols] | |
(list* 'do | |
(map foo symbols (range)))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def event-probability-distribution {:red 20 :green 50 :yellow 30}) | |
(def color-generator (utils.core/random-event-generator event-probability-distribution)) | |
(def random-colors (repeatedly color-generator)) | |
(def sample (take 100 random-colors)) | |
(frequencies sample) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest team-score-updation | |
(testing "Keeps team score when no run scored" | |
(on-game (helper/add-dot-ball-to-game-on-over game [0 1]) | |
(is-total-score? 0) | |
(is-on-over? [0 1]) | |
(is-striker? "Kirat Boli") | |
(is-non-striker? "N S Nodhi"))) | |
(testing "Updates team score and rotates strike when single run scored" | |
(on-game (helper/add-single-run-to-game-on-over game [0 1]) | |
(is-total-score? 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns learning-reagent.core | |
(:require [reagent.core :as reagent])) | |
;; ------------------------- | |
;; Views | |
(defn fibo | |
([] (fibo 1 1)) | |
([s1 s2] (lazy-seq (cons s1 (fibo s2 (+ s1 s2)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fibo=function(n) { | |
if (n<=0) | |
return []; | |
if(n<3) | |
return [1,0].slice(0,n); | |
var a=Array.apply(null,new Array(n-2)); | |
return a.reduce(function(l,x){ | |
l.unshift(l[0]+l[1]); | |
return l; | |
},[1,0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fibo [s1 s2] | |
(lazy-seq (cons s1 (fibo s2 (+ s1 s2))))) | |
(defn fibo-even (comp (partial filter even?) fibo)) | |
(def fibonacci (fibo 1 1)) | |
(def fibonacci-even (fibo-even 1 1)) | |
(take 10 fibonacci) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var printFibo=function(n) { | |
var s1=0; | |
var s2=1; | |
var s3; | |
for (var i = 0; i < n; i++) { | |
console.log(s2); | |
s3=s1+s2; | |
s1=s2; | |
s2=s1+s2; | |
} |