Created
April 22, 2011 17:21
-
-
Save anonymous/937140 to your computer and use it in GitHub Desktop.
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
;; 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