Skip to content

Instantly share code, notes, and snippets.

@coldnew
Forked from ponzao/tictactoe.clj
Last active August 29, 2015 14:22
Show Gist options
  • Save coldnew/8cf373006d0caa1c3df9 to your computer and use it in GitHub Desktop.
Save coldnew/8cf373006d0caa1c3df9 to your computer and use it in GitHub Desktop.
(defn solve
[grid]
(remove nil?
(run* [q]
(macro/symbol-macrolet [_ (lvar)]
(== q grid)
(conde
((== grid [[q _ _]
[_ q _]
[_ _ q]]))
((== grid [[_ _ q]
[_ q _]
[q _ _]]))
((== grid [[q _ _]
[q _ _]
[q _ _]]))
((== grid [[_ q _]
[_ q _]
[_ q _]]))
((== grid [[_ _ q]
[_ _ q]
[_ _ q]]))
((== grid [[q q q]
[_ _ _]
[_ _ _]]))
((== grid [[_ _ _]
[q q q]
[_ _ _]]))
((== grid [[_ _ _]
[_ _ _]
[q q q]])))))))
(solve [[:y :x :y]
[nil :x nil]
[nil :x nil]])
; => (:x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment