Skip to content

Instantly share code, notes, and snippets.

View chrisvest's full-sized avatar
🍉

Chris Vest chrisvest

🍉
View GitHub Profile
;; 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
;; chrisvest's solution to http://4clojure.com/problem/67
(fn [n] (let [start (java.math.BigInteger. "2")]
(take n (map #(.intValue %) (iterate #(.nextProbablePrime %) start)))))
;; chrisvest's solution to http://4clojure.com/problem/70
(fn [s] (->> s (re-seq #"[a-zA-Z]+") (sort-by #(.toLowerCase %))))
;; 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)))
;; chrisvest's solution to http://4clojure.com/problem/62
(fn itr [f x]
(lazy-seq (cons x (itr f (f x)))))
;; chrisvest's solution to http://4clojure.com/problem/61
(fn [ks vs] (into {} (map vector ks vs)))
;; chrisvest's solution to http://4clojure.com/problem/59
(fn [& fs]
(fn [& args] (map #(apply % args) fs)))
;; 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)))
;; chrisvest's solution to http://4clojure.com/problem/55
(fn [xs]
(->> (group-by identity xs)
(map (fn [[k v]] (vector k (count v))))
(into {})))
;; 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)))