Skip to content

Instantly share code, notes, and snippets.

@coffeemancy
Created September 25, 2014 03:23
Show Gist options
  • Save coffeemancy/74ac4bbb3ea8ddbe73c0 to your computer and use it in GitHub Desktop.
Save coffeemancy/74ac4bbb3ea8ddbe73c0 to your computer and use it in GitHub Desktop.
2048 collapse row clojure
(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