Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2011 17:21
Show Gist options
  • Save anonymous/937140 to your computer and use it in GitHub Desktop.
Save anonymous/937140 to your computer and use it in GitHub Desktop.
;; peteris's solution to http://4clojure.com/problem/31
#(let [[elt cnt]
(let [v (vec %), n (count %)]
(loop [i 1, elt [(first v)], cnt [1]]
(if (= i n)
[elt cnt]
(recur (inc i)
(if (= (v i) (v (dec i)))
elt
(conj elt (v i)))
(if (= (v i) (v (dec i)))
(assoc cnt (dec (count cnt)) (inc (cnt (dec (count cnt)))))
(conj cnt 1))))))]
(for [i (range (count elt))]
(take (cnt i) (repeat (elt i)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment