Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from martintrojer/sud4-ckanren.clj
Created July 27, 2012 19:41
Show Gist options
  • Save swannodette/3190095 to your computer and use it in GitHub Desktop.
Save swannodette/3190095 to your computer and use it in GitHub Desktop.
Sudoku core.logic
(defne all-distinctfd [l]
([()])
([[h . t]]
(distinctfd h)
(all-distinctfd t)))
(run 1 [q]
(fresh [a1 a2 a3 a4
b1 b2 b3 b4
c1 c2 c3 c4
d1 d2 d3 d4]
(== q [[a1 a2 a3 a4]
[b1 b2 b3 b4]
[c1 c2 c3 c4]
[d1 d2 d3 d4]])
(infd a1 a2 a3 a4
b1 b2 b3 b4
c1 c2 c3 c4
d1 d2 d3 d4
(interval 1 6)) ;; <- Must be bumped to 6 for it to work?
(let [row1 [a1 a2 a3 a4]
row2 [b1 b2 b3 b4]
row3 [c1 c2 c3 c4]
row4 [d1 d2 d3 d4]
col1 [a1 b1 c1 d1]
col2 [a2 b2 c2 d2]
col3 [a3 b3 c3 d3]
col4 [a4 b4 c4 d4]
sq1 [a1 a2 b1 b2]
sq2 [a3 a4 b3 b4]
sq3 [c1 c2 d1 d2]
sq4 [c3 c4 d3 d4]]
(all-distinctfd [row1 row2 row3 row4
col1 col2 col3 col4
sq1 sq2 sq3 sq4
]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment