I had some trouble because all goals need to take in the list of lvars.
`infd` doesn't take in a list, but your sudoku blog post has `all-infd`
which does the trick:
(defn all-infd
"Assign a domain to all vars."
[vars domain]
(if (seq vars)
(all
(domfd (first vars) domain)
(all-infd (next vars) domain))
succeed))
Which means that `distinct-numbers` can be written as such:
(defn distinct-numbers [n min max]
"Generate all combinations of n numbers between min and max."
(run* [q]
(let [vars (repeatedly n lvar)]
(all
(all-infd vars (interval min max))
(distinctfd vars)
(== q vars)))))
user=> (distinct-numbers 3 6 8)
((6 7 8) (6 8 7) (7 6 8) (7 8 6) (8 6 7) (8 7 6))
Thanks for the help!
Frederik
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en