Skip to content

Instantly share code, notes, and snippets.

@biesnecker
Created January 22, 2012 01:07
Show Gist options
  • Save biesnecker/1654875 to your computer and use it in GitHub Desktop.
Save biesnecker/1654875 to your computer and use it in GitHub Desktop.
#73 Analyze a Tic-Tac-Toe Board
#(some {[:o :o :o] :o [:x :x :x] :x}
(partition 3
(map
(vec (flatten %))
[0 1 2 3 4 5 6 7 8
0 3 6 1 4 7 2 5 8
0 4 8 2 4 6])))
(fn [board]
(let [
diags (fn [b] (split-at 3 (map #(nth (flatten b) %) '(0 4 8 2 4 6))))
verts (fn [b] (apply map list b))
combos (concat board (diags board) (verts board))
filter-s (filter #(= (count %) 1) (map distinct combos))
filter-e (filter #(not= (first %) :e) filter-s)
]
(ffirst filter-e)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment