Created
September 10, 2010 22:32
-
-
Save apg/574494 to your computer and use it in GitHub Desktop.
same-game functional merge board-left
This file contains 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
(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