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
([:a, :b, :c].zip([1,2,3])).inject({}){|res, ele| res[ele.first] = ele.last; res} #=> {:c=>3, :a=>1, :b=>2} |
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
;http://4clojure.com/problem/22 | |
#(loop [coll % cnt 0] | |
(if (empty? coll) | |
cnt | |
(recur (next coll) (inc cnt)))) |
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
;http://4clojure.com/problem/23 | |
#(loop [coll % stk []] | |
(if (empty? coll) | |
stk | |
(recur (next coll) (cons (first coll) stk)))) |
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
;http://4clojure.com/problem/26 | |
#(loop [n % seq []] | |
(letfn [(fib [x] | |
(if (<= x 2) | |
1 | |
(+ (fib (- x 2)) (fib(- x 1)))))] | |
(if (= n 0) | |
seq | |
(recur (dec n) (cons (fib n) seq))))) |
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
;http://4clojure.com/problem/32 | |
#(loop [col % c ()] | |
(if (empty? col) | |
(reverse c) | |
(recur (rest col) | |
(cons (first col) (cons (first col) c))))) |
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
;http://4clojure.com/problem/34 | |
#(loop [from %1 to %2 c ()] | |
(if (= from to) | |
(reverse c) | |
(recur (inc from) to (conj c from)))) |
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
#(loop [col % c ()] | |
(cond (empty? col) (reverse c) | |
(= (first col) (first c)) (recur (rest col) c) | |
:else (recur (rest col) (cons (first col) c)))) |
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
;http://4clojure.com/problem/42 | |
#(loop [n % f 1] | |
(if (= n 1) | |
f | |
(recur (dec n) (* f n)))) |
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
#(loop [coll %1 n %2 c ()] | |
(if (empty? coll) | |
(reverse c) | |
(recur (rest coll) n (into c (repeat n (first coll)))))) |
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
#(loop [f %1 s %2 c ()] | |
(if (or | |
(empty? f) | |
(empty? s)) | |
(reverse c) | |
(recur (rest f) (rest s) (conj c (first f) (first s))))) |
OlderNewer