I'm finally getting around to looking at the Sudoku program. I took Raph's version of Filip's earlier version and broke it up into pieces so that it would be (even) easier (for me) to read. It's on the course wiki at
http://cs.calstatela.edu/~wiki/index.php/Courses/CS_460/Fall_2005/Simplified_Sudoku_Solver.
Originally, I thought it would be interesting to use this brute force version (require all the rows, columns, and subgrids to be distinct) as a baseline and then add some of the standard Sudoku deduction rules. But FD solves it in such short order even as a brute force problem, that it hardly seems worth the trouble.
-- Russ
P.S. Am I right that the input grid must be cloned because you can't export values to it? When I don't do that I don't get an answer.
On 9/25/05, Raphael Collet <[EMAIL PROTECTED]> wrote:
Filip Konvicka wrote:
> Some time ago, I have created a simple Sudoku script for my co-workers
> to show them Oz basics. It's just a straightforward implementation (and
> maybe a bit clumsy).
Your solution is pretty hard to read. I have tried to simplify it a
bit, see the attachment.
Cheers,
raph
local
fun {Script Spec}
proc {$ Root}
%% tuples are more efficient than lists
Root={List.make 9}
for Row in Root do Row={FD.list 9 1#9} end
%% All numbers in each row are distinct
{ForAll Root FD.distinct }
%% All numbers in each column are distinct
for I in 1..9 do
{FD.distinct {Map Root fun {$ Row} {Nth Row I} end}}
end
%% All numbers in each 3x3 square are distinct
for I in 0..2 do
RowOfSquares={List.take {List.drop Root I*3} 3}
in
for J in 0..2 do
Elems = for Row in RowOfSquares append:App do
{App { List.take {List.drop Row J*3} 3}}
end
in
{FD.distinct Elems}
end
end
%% constrain Root with Spec; simply unify Root with a clone
%% of Spec
Root = {Map Spec
fun {$ Row}
{Map Row
fun {$ X} if {IsDet X} then X else _ end end}
end}
%% Search...
{FD.distribute ff {FoldR Root Append nil}}
end
end
in
{Show {SearchOne
{Script [[_ 9 _ 3 _ _ _ 1 _]
[2 _ 3 _ _ 1 _ _ _]
[_ _ _ _ 7 5 _ 8 _]
[_ _ 2 _ _ _ _ 5 6]
[_ _ _ 7 _ 8 _ _ _]
[7 1 _ _ _ _ 2 _ _]
[_ 2 _ 4 9 _ _ _ _]
[_ _ _ 8 _ _ 5 _ 1]
[_ 7 _ _ _ 2 _ 9 _]]}}}
end
_________________________________________________________________________________
mozart-users mailing list [email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
