This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/74 | |
(fn [s] | |
(let [perfect-square | |
(fn [n] (loop [i 1] | |
(cond | |
(= n (* i i)) true | |
(< n (* i i)) false | |
:else (recur (inc i)))))] | |
(->> s |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/67 | |
(fn [n] (let [start (java.math.BigInteger. "2")] | |
(take n (map #(.intValue %) (iterate #(.nextProbablePrime %) start))))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/70 | |
(fn [s] (->> s (re-seq #"[a-zA-Z]+") (sort-by #(.toLowerCase %)))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/69 | |
(fn [f m & ms] | |
(let [kvs (mapcat seq ms) | |
mrg (fn [hm [k v]] | |
(assoc hm k (if-let [ev (hm k)] (f ev v) v)))] | |
(reduce mrg m kvs))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/62 | |
(fn itr [f x] | |
(lazy-seq (cons x (itr f (f x))))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/61 | |
(fn [ks vs] (into {} (map vector ks vs))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/59 | |
(fn [& fs] | |
(fn [& args] (map #(apply % args) fs))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/56 | |
(fn [xs] (first | |
(reduce (fn [[l s] x] (if (s x) [l s] [(conj l x) (conj s x)])) | |
[[] #{}] xs))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/55 | |
(fn [xs] | |
(->> (group-by identity xs) | |
(map (fn [[k v]] (vector k (count v)))) | |
(into {}))) |
This file contains 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
;; chrisvest's solution to http://4clojure.com/problem/54 | |
(fn [n xs] | |
(let [len (count xs) | |
stops (range 0 (- len (mod len n)) n)] | |
(map (fn [x] (subvec (vec xs) x (+ x n))) stops))) |