Created
June 8, 2013 21:31
-
-
Save swannodette/5736688 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 get-square [rows x y] | |
(for [x (range x (+ x 3)) | |
y (range y (+ y 3))] | |
(get-in rows [x y]))) | |
(defn init [vars hints] | |
(if (seq vars) | |
(let [hint (first hints)] | |
(all | |
(if-not (zero? hint) | |
(== (first vars) hint) | |
succeed) | |
(init (next vars) (next hints)))) | |
succeed)) | |
(defn ->rows [xs] | |
(->> xs (partition 9) (map vec) (into []))) | |
(defn ->cols [rows] | |
(apply map vector rows)) | |
(defn ->squares [rows] | |
(for [x (range 0 9 3) | |
y (range 0 9 3)] | |
(get-square rows x y))) | |
(defn sudokufd [hints] | |
(let [vars (repeatedly 81 lvar) | |
rows (->rows vars) | |
cols (->cols rows) | |
sqs (->squares rows)] | |
(run-nc 1 [q] | |
(== q vars) | |
;;(distribute q ::l/ff) | |
(everyg #(fd/in % (fd/domain 1 2 3 4 5 6 7 8 9)) vars) | |
(init vars hints) | |
(everyg fd/distinct rows) | |
(everyg fd/distinct cols) | |
(everyg fd/distinct sqs)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🍻