Created
April 1, 2012 05:25
-
-
Save anonymous/2271656 to your computer and use it in GitHub Desktop.
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
;; ariarule's solution to Win at Tic-Tac-Toe | |
;; https://4clojure.com/problem/119 | |
(fn [player board] | |
(let [vboard (apply concat board) | |
s (range 0 3) | |
positions (mapcat #(map (fn [x] [% x]) s) s) | |
rows (partition 3 positions) | |
columns [(map first rows) (map second rows) (map #(nth % 2) rows)] | |
wins (map set (concat rows columns ['([0 0] [1 1] [2 2]) '([0 2] [1 1] [2 0])])) | |
piece-positions (zipmap positions vboard) | |
[player-positions empty-positions] (map set (map (fn [x] (map first (filter #(= (val %) x) piece-positions))) [player :e])) | |
] | |
(set | |
(filter #(-> % nil? not) (map #(if (some | |
(fn [w] | |
(clojure.set/subset? w (conj player-positions %))) | |
wins) | |
%) | |
empty-positions))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment