-
-
Save tutysara/3218266 to your computer and use it in GitHub Desktop.
sudoku_compact.clj
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
(ns sudoku | |
(:refer-clojure :exclude [==]) | |
(:use clojure.core.logic)) | |
(defn get-square [grid x y] | |
(for [x (range x (+ x 3)) | |
y (range y (+ y 3))] | |
(get-in grid [x y]))) | |
(defn init [grid [pos value]] | |
(== (get-in grid pos) value)) | |
(defn sudokufd [initial] | |
(let [vs (repeatedly 81 lvar) | |
grid (->> vs (partition 9) (map vec) (into [])) | |
rows grid | |
cols (apply map vector grid) | |
sqs (for [x (range 0 9 3) | |
y (range 0 9 3)] | |
(get-square grid x y))] | |
(run-nc 1 [q] | |
(== q grid) | |
(everyo #(infd % (domain 1 2 3 4 5 6 7 8 9)) vs) | |
(everyo (partial init grid) initial) | |
(everyo distinctfd rows) | |
(everyo distinctfd cols) | |
(everyo distinctfd sqs)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment