Created
September 25, 2014 03:23
-
-
Save coffeemancy/74ac4bbb3ea8ddbe73c0 to your computer and use it in GitHub Desktop.
2048 collapse row clojure
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
(defn collapse-row [row] | |
(filterv (complement nil?) | |
(reduce (fn [acc elm] | |
(let [n (peek acc)] | |
(if (= n elm) | |
(conj (pop acc) (* n 2) nil) | |
(conj acc elm)))) | |
[nil] | |
row))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment