Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2011 12:26
Show Gist options
  • Select an option

  • Save anonymous/1505853 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1505853 to your computer and use it in GitHub Desktop.
;; jgustak's solution to Analyze a Tic-Tac-Toe Board
;; https://4clojure.com/problem/73
(fn tictac [mtx]
(let [xs (concat mtx
(vec (apply map vector mtx))
[(for [x [0 1 2]] (get-in mtx [x x]))
(for [x [0 1 2]] (get-in mtx [x (- 2 x)]))])
who (fn [ys]
(and (apply = ys) (not= (first ys) :e) (first ys)))]
(loop [xs xs]
(when (seq xs)
(if-let [winner (who (first xs))]
winner
(recur (rest xs)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment