I am going through the 4clojure problems and I currently just solved the Tic Tac Toe analyzer:
(fn [board]
(let [vr (for [x (range 3)]
(get-in board[(+ x 0) (+ x 0)]))
vl (for [x (range 3)]
(get-in board [(+ x) (- 2 x)]))
columns (apply map vector board)
checks (concat board [vl] [vr] columns)]
(letfn [(check-board [[row & res]]
(if row
(let [dist (distinct row)]
(if (or (= dist [:o]) (= dist [:x]))
(first dist)
(check-board res)))
nil))]
(check-board checks))))
I'm looking for any feedback about how I could make the code more terse.
Could I have created the diagonal vectors in one expression?
I don't like that I had to use recursion but I could not think of a way of using something like reduce because I don't think there is a way to short circuit reduce if you find the result midway through processing all the values.
Is there a way that I could avoid recursion with this problem?