Last active
April 8, 2016 18:57
-
-
Save freckletonj/3972847c60250edb37a31f132c70239c to your computer and use it in GitHub Desktop.
Clojure core.logic puzzle #01
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* [q] | |
(fresh [al finn irv jim | |
p1 p2 p3 p4 | |
y1 y2 y3 y4] | |
;; rule #1 --------- | |
;; Of the item that sold for $175 and the one that sold for $225, | |
;; one featured Irv Ingram and the other came out in 1983. | |
(conde | |
((== irv [:175 (lvar)]) | |
(membero [:225 :1983] [al finn jim])) | |
((== irv [:225 (lvar)]) | |
(membero [:175 :1983] [al finn jim]))) | |
;; rule #2 --------- | |
;; 83. | |
;; Al Allison's card was either the piece that sold for $125 or the 1988 piece. | |
(conde | |
((== al [:125 (lvar)])) | |
((== al [(lvar) :1988]))) | |
(!= al [:125 :1988]) | |
;; rule #3 --------- | |
;; Of the 1978 item and the card that sold for $225, | |
;; one featured Finn Freeman and the other featured Irv Ingram. | |
(conde | |
((== irv [:225 (lvar)]) | |
(== finn [(lvar) :1978])) | |
((== irv [(lvar) :1978]) | |
(== finn [:225 (lvar)]))) | |
;; rule #4 --------- | |
;; Al Allison's piece sold for 50 dollars less than Irv Ingram's card. | |
(conde | |
((== al [:125 (lvar)]) | |
(== irv [:175 (lvar)])) | |
((== al [:175 (lvar)]) | |
(== irv [:225 (lvar)])) | |
((== al [:225 (lvar)]) | |
(== irv [:275 (lvar)]))) | |
(== al [p1 y1]) | |
(== finn [p2 y2]) | |
(== irv [p3 y3]) | |
(== jim [p4 y4]) | |
(permuteo [:125 :175 :225 :275] [p1 p2 p3 p4]) | |
(permuteo [:1978 :1983 :1988 :1999] [y1 y2 y3 y4]) | |
(== q {:al al | |
:finn finn | |
:irv irv | |
:jim jim}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment