Skip to content

Instantly share code, notes, and snippets.

@mlb-
Created October 6, 2015 02:21
Show Gist options
  • Save mlb-/9d5626ad341f0ab1929a to your computer and use it in GitHub Desktop.
Save mlb-/9d5626ad341f0ab1929a to your computer and use it in GitHub Desktop.
(defn win-tic-tac-toe
[side b]
(let [b (->> b
flatten
(map-indexed vector))
check-win (fn
[[a b c d e f g h i]]
(->> [[a b c] [d e f] [g h i]
[a d g] [b e h] [c f i]
[a e i] [c e g]]
(filter (partial apply =))
(map first)
(drop-while (partial = :e))
first))]
(->> b
(filter #(= :e (second %)))
(map first)
(filter (comp check-win
vals
#(assoc (into (sorted-map) b) % side)))
(map (juxt #(quot % 3) #(mod % 3)))
(into #{}))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment