On 07/08/12 13:19, David Nolen wrote:
(= (- x a) (- y b))
Is not going to work. You probably want.
(project [x y a b]
(== (- x a) (- y b)))
Though of course isn't relational. This kind of thing is probably now
better handled by the new CLP(FD) functionality. I'm planning on
adding some sugar / inference to make this kind of thing less tedious.
Thanks a million David! my final solution is this:
(defn bishop-moves [x y]
(let [board [0 1 2 3 4 5 6 7]]
(run* [q]
(fresh [a b]
(membero a board)
(membero b board)
(!= a x)
(!= b y)
(project [x y a b]
(== (Math/abs (- x a))
(Math/abs (- y b)))
(== q [a b]))))))
So far the castel has been the easiest!
(defn castle-moves [x y]
(let [board [0 1 2 3 4 5 6 7]]
(run* [q]
(fresh [a b]
(conde
[(membero a board) (!= a x) (== b y)]
[(membero b board) (!= b y) (== a x)])
(== q [a b])))))
Thanks again!
Jim
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en