Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created June 8, 2013 21:31
Show Gist options
  • Save swannodette/5736688 to your computer and use it in GitHub Desktop.
Save swannodette/5736688 to your computer and use it in GitHub Desktop.
(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))))
@clifton
Copy link

clifton commented Aug 21, 2013

🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment