Skip to content

Instantly share code, notes, and snippets.

@apg
Created September 10, 2010 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apg/574494 to your computer and use it in GitHub Desktop.
Save apg/574494 to your computer and use it in GitHub Desktop.
same-game functional merge board-left
(ns dummy.core
:use [[clojure.contrib.seq-utils :only [indexed]]])
(defn find-all
[coll x]
(keep-indexed #(if (= x %2) %1) coll))
(defn merge-left-row [coll idx]
(let [front (map second
(filter #(not (contains? idx (first %)))
(take (count coll) (indexed coll))))]
(concat front (take (- (count coll) (count front))
(repeat nil)))))
(defn merge-left [coll]
(let [idx (apply sorted-set (find-all (last coll) nil))]
(map merge-left-row coll (repeat idx))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment