Skip to content

Instantly share code, notes, and snippets.

@fronx
Forked from anonymous/fronx-4clojure-solution73.clj
Created September 16, 2011 17:49
Show Gist options
  • Save fronx/1222682 to your computer and use it in GitHub Desktop.
Save fronx/1222682 to your computer and use it in GitHub Desktop.
fronx's solution to Analyze a Tic-Tac-Toe Board ;; https://4clojure.com/problem/73
;; fronx's solution to Analyze a Tic-Tac-Toe Board
;; https://4clojure.com/problem/73
(fn [m]
(first
(filter
(fn win? [player]
(->> (let [idx [0 1 2]]
(concat m ; rows
(map (fn [i] (map #(% i) m)) idx) ; columns
(vector (map #((m %) %) idx)) ; diagonal 1
(vector (map #((m (- 2 %)) %) idx)))) ; diagonal 2
(map (fn [row] (count (filter #(= player %) row))))
(filter #(= % 3))
seq))
[:x :o])))
; [
; ; rows
; [a b c]
; [d e f]
; [g h i]
; ; columns
; [a d g]
; [b e h]
; [c f i]
; ; diagonals
; [a e i]
; [g e c]
; ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment