Created
July 7, 2012 11:28
-
-
Save martintrojer/3065962 to your computer and use it in GitHub Desktop.
queens blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def subo | |
(fn ([x y r] | |
(conde | |
[(== x 0) (== y 0) (== r 0)] | |
[(== x 0) (== y 1) (== r -1)] | |
[(== x 1) (== y 0) (== r 1)] | |
[(== x 1) (== y 1) (== r 0)])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(run* [r] | |
(fresh [x1 x2 x3 x4] | |
(safeo [x1 0] [x2 1]) | |
(safeo [x1 0] [x3 2]) | |
(safeo [x1 0] [x4 3]) | |
(safeo [x2 1] [x3 2]) | |
(safeo [x2 1] [x4 3]) | |
(safeo [x3 2] [x4 3]) | |
(== r [[x1 0] [x2 1] [x3 2] [x4 3]])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn safe? [[x1 y1] [x2 y2]] | |
(and | |
(not= x1 x2) | |
(not= y1 y2) | |
(not= (- x2 x1) (- y2 y1)) | |
(not= (- x1 y2) (- x2 y1)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn safeo | |
"Are 2 queens threatening each ohter?" | |
[[x1 y1] [x2 y2]] | |
(fresh [d1 d2 d3 d4] | |
(subo x2 x1 d1) | |
(subo y2 y1 d2) | |
(subo x1 y2 d3) | |
(subo x2 y1 d4) | |
(!= x1 x2) | |
(!= y1 y2) | |
(!= d1 d2) | |
(!= d3 d4))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment