Courses/CS 460/Fall 2005/Homework/Joey Leung/Dec 3

From CSWiki

Jump to: navigation, search

[edit] Finite Sets Sudoku Solver

Does not work. Could not figure out how to get the set for the block, and then couldn't go any futher.


declare

proc {Sudoku Problem Result}
   Row Column Block Set
in
   {FS.var.list.upperBound 9 [1#81] Set}
   {ForAll Set proc {$ Problem} {FS.card Problem 9} end}
   
   {For 1 81 1
    proc {$ I}
       if {IsDet {Nth Problem I}} then
	  {FS.include I {Nth Set {Nth Problem I}}}
       else skip end
    end}
   
   {For 1 9 1
    proc {$ I} Row in
       Row = {List.number (I-1)*9+1 I*9 1}
       {FS.var.bounds Row Row {Nth Row I}}
    end}

   {For 1 9 1
    proc {$ I} Column in
       Column = {List.number I 81 9}
       {FS.var.bounds Column Column {Nth Column I}}
    end }

   {For 1 9 1
    proc {$ I} Block in
       Block = {GetBlock I}
       {FS.var.bounds Block Block {Nth Block I}}
    end}

   {For 1 9 1
    proc {$ I}
       {For 1 9 1
	proc {$ J}
	   {FS.card {FS.intersect {Nth Result I} {Nth Row J}} 1}
	   {FS.card {FS.intersect {Nth Result I} {Nth Column J}} 1}
	   {FS.card {FS.intersect {Nth Result I} {Nth Block J}} 1}
	end
       }
    end
   }
   
   {FS.disjointN Set}
   {FS.distribute naive Set}
   Result = Set
end

proc {GetBlock N ?L}
   Block Start = [1 4 7 28 31 34 55 58 61]
in
   
end

proc {ShowSudoku Set ?Result}

end

Problem =
[
 _ 5 _  _ 4 _  _ _ 7
 _ _ _  1 _ _  _ _ 3
 _ 9 _  _ _ 8  _ 6 _
 _ _ 2  _ _ _  8 _ _
 _ 6 _  _ _ 9  _ 5 _
 _ _ 1  _ 7 _  4 _ _
 _ 3 _  2 _ _  _ 9 _
 8 _ _  _ _ 6  _ _ _
 4 _ _  _ 3 _  _ 1 _
]

{Browse {SearchAll fun {$} {Sudoku Problem} end}}