Courses/CS 460/Fall 2005/Homework/Kelly Breed/Dec 3

From CSWiki

Jump to: navigation, search

[edit] HW 9

[edit] Sudoku Solver Using Finite Sets

A collaboration by Jay Donnell and Kelly Breed

declare
%% Some Sudoku puzzles:
Prob =
[x 6 x 1 x 4 x 5 x
 x x 8 3 x 5 6 x x
 2 x x x x x x x 1
 8 x x 4 x 7 x x 6
 x x 6 x x x 3 x x
 7 x x 9 x 1 x x 4
 5 x x x x x x x 2
 x x 7 2 x 6 9 x x
 x 4 x 5 x 8 x 7 x]

 Prob2 =
[x x x 3 4 2 x x x
 5 4 x x 7 x x 8 x
 x x 2 x x 5 4 x 6
 x 6 x 2 x x x x x
 3 x 8 x x x 2 x 4
 x x x x x 8 x 7 x
 6 x 9 1 x x 5 x x
 x 3 x x 8 x x 1 9
 x x x 5 3 9 x x x]

Fiendish =
[x x x x x x x 1 4
 2 x x 5 x x 6 x x
 9 x x 3 x x x x x
 x 5 x x 1 x x 3 x
 x 8 x x 3 x x 7 x
 x 6 x x 2 x x 9 x
 x x x x x 8 x x 2
 x x 3 x x 4 x x 1
 5 7 x x x x x x x]

Blank =
[x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x
 x x x x x x x x x]

proc {Sudoku Puz Sol}

   %% Take the values from the puzzle and put appropriate entries into the solution sets.
   {For 1 81 1
    proc {$ N}
       if {Nth Puz N}==x then skip
       else {FS.include N {Nth Sol {Nth Puz N}}}
       end
    end
   }
   
      Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9
      Row1 Row2 Row3 Row4 Row5 Row6 Row7 Row8 Row9
      Block1 Block1 Block2 Block3 Block4 Block5 Block6 Block7 Block8 Block9
   in
      {FS.var.list.upperBound 9 [1#81] Sol}
      {ForAll Sol proc {$ V} {FS.card V 9} end}

      Row1 = {FS.var.bounds [1#9][1#9]}
      Row2 = {FS.var.bounds [10#18][10#18]}
      Row3 = {FS.var.bounds [19#27][19#27]}
      Row4 = {FS.var.bounds [28#36][28#36]}
      Row5 = {FS.var.bounds [37#45][37#45]}
      Row6 = {FS.var.bounds [46#54][46#54]}
      Row7 = {FS.var.bounds [55#63][55#63]}
      Row8 = {FS.var.bounds [64#72][64#72]}
      Row9 = {FS.var.bounds [73#81][73#81]}

      Col1 = {FS.var.upperBound [1#81]}
      {FS.card Col1 9}
      {FS.include 1 Col1}
      {FS.include 10 Col1}
      {FS.include 19 Col1}
      {FS.include 28 Col1}
      {FS.include 37 Col1}
      {FS.include 46 Col1}
      {FS.include 55 Col1}
      {FS.include 64 Col1}
      {FS.include 73 Col1}

      Col2 = {FS.var.upperBound [1#81]}
      {FS.card Col2 9}
      {FS.include 2 Col2}
      {FS.include 11 Col2}
      {FS.include 20 Col2}
      {FS.include 29 Col2}
      {FS.include 38 Col2}
      {FS.include 47 Col2}
      {FS.include 56 Col2}
      {FS.include 65 Col2}
      {FS.include 74 Col2}

      Col3 = {FS.var.upperBound [1#81]}
      {FS.card Col3 9}
      {FS.include 3 Col3}
      {FS.include 12 Col3}
      {FS.include 21 Col3}
      {FS.include 30 Col3}
      {FS.include 39 Col3}
      {FS.include 48 Col3}
      {FS.include 57 Col3}
      {FS.include 66 Col3}
      {FS.include 75 Col3}

      Col4 = {FS.var.upperBound [1#81]}
      {FS.card Col4 9}
      {FS.include 4 Col4}
      {FS.include 13 Col4}
      {FS.include 22 Col4}
      {FS.include 31 Col4}
      {FS.include 40 Col4}
      {FS.include 49 Col4}
      {FS.include 58 Col4}
      {FS.include 67 Col4}
      {FS.include 76 Col4}

      Col5 = {FS.var.upperBound [1#81]}
      {FS.card Col5 9}
      {FS.include 5 Col5}
      {FS.include 14 Col5}
      {FS.include 23 Col5}
      {FS.include 32 Col5}
      {FS.include 41 Col5}
      {FS.include 50 Col5}
      {FS.include 59 Col5}
      {FS.include 68 Col5}
      {FS.include 77 Col5}

      Col6 = {FS.var.upperBound [1#81]}
      {FS.card Col6 9}
      {FS.include 6 Col6}
      {FS.include 15 Col6}
      {FS.include 24 Col6}
      {FS.include 33 Col6}
      {FS.include 42 Col6}
      {FS.include 51 Col6}
      {FS.include 60 Col6}
      {FS.include 69 Col6}
      {FS.include 78 Col6}

      Col7 = {FS.var.upperBound [1#81]}
      {FS.card Col7 9}
      {FS.include 7 Col7}
      {FS.include 16 Col7}
      {FS.include 25 Col7}
      {FS.include 34 Col7}
      {FS.include 43 Col7}
      {FS.include 52 Col7}
      {FS.include 61 Col7}
      {FS.include 70 Col7}
      {FS.include 79 Col7}

      Col8 = {FS.var.upperBound [1#81]}
      {FS.card Col8 9}
      {FS.include 8 Col8}
      {FS.include 17 Col8}
      {FS.include 26 Col8}
      {FS.include 35 Col8}
      {FS.include 44 Col8}
      {FS.include 53 Col8}
      {FS.include 62 Col8}
      {FS.include 71 Col8}
      {FS.include 80 Col8}

      Col9 = {FS.var.upperBound [1#81]}
      {FS.card Col9 9}
      {FS.include 9 Col9}
      {FS.include 18 Col9}
      {FS.include 27 Col9}
      {FS.include 36 Col9}
      {FS.include 45 Col9}
      {FS.include 54 Col9}
      {FS.include 63 Col9}
      {FS.include 72 Col9}
      {FS.include 81 Col9}

      Block1 = {FS.var.upperBound [1#81]}
      {FS.card Block1 9}
      {FS.include 1 Block1}
      {FS.include 2 Block1}
      {FS.include 3 Block1}
      {FS.include 10 Block1}
      {FS.include 11 Block1}
      {FS.include 12 Block1}
      {FS.include 19 Block1}
      {FS.include 20 Block1}
      {FS.include 21 Block1}

      Block2 = {FS.var.upperBound [1#81]}
      {FS.card Block2 9}
      {FS.include 4 Block2}
      {FS.include 5 Block2}
      {FS.include 6 Block2}
      {FS.include 13 Block2}
      {FS.include 14 Block2}
      {FS.include 15 Block2}
      {FS.include 22 Block2}
      {FS.include 23 Block2}
      {FS.include 24 Block2}

      Block3 = {FS.var.upperBound [1#81]}
      {FS.card Block3 9}
      {FS.include 7 Block3}
      {FS.include 8 Block3}
      {FS.include 9 Block3}
      {FS.include 16 Block3}
      {FS.include 17 Block3}
      {FS.include 18 Block3}
      {FS.include 25 Block3}
      {FS.include 26 Block3}
      {FS.include 27 Block3}

      Block4 = {FS.var.upperBound [1#81]}
      {FS.card Block4 9}
      {FS.include 28 Block4}
      {FS.include 29 Block4}
      {FS.include 30 Block4}
      {FS.include 37 Block4}
      {FS.include 38 Block4}
      {FS.include 39 Block4}
      {FS.include 46 Block4}
      {FS.include 47 Block4}
      {FS.include 48 Block4}

      Block5 = {FS.var.upperBound [1#81]}
      {FS.card Block5 9}
      {FS.include 31 Block5}
      {FS.include 32 Block5}
      {FS.include 33 Block5}
      {FS.include 40 Block5}
      {FS.include 41 Block5}
      {FS.include 42 Block5}
      {FS.include 49 Block5}
      {FS.include 50 Block5}
      {FS.include 51 Block5}

      Block6 = {FS.var.upperBound [1#81]}
      {FS.card Block6 9}
      {FS.include 34 Block6}
      {FS.include 35 Block6}
      {FS.include 36 Block6}
      {FS.include 43 Block6}
      {FS.include 44 Block6}
      {FS.include 45 Block6}
      {FS.include 52 Block6}
      {FS.include 53 Block6}
      {FS.include 54 Block6}

      Block7 = {FS.var.upperBound [1#81]}
      {FS.card Block7 9}
      {FS.include 55 Block7}
      {FS.include 56 Block7}
      {FS.include 57 Block7}
      {FS.include 64 Block7}
      {FS.include 65 Block7}
      {FS.include 66 Block7}
      {FS.include 73 Block7}
      {FS.include 74 Block7}
      {FS.include 75 Block7}

      Block8 = {FS.var.upperBound [1#81]}
      {FS.card Block8 9}
      {FS.include 58 Block8}
      {FS.include 59 Block8}
      {FS.include 60 Block8}
      {FS.include 67 Block8}
      {FS.include 68 Block8}
      {FS.include 69 Block8}
      {FS.include 76 Block8}
      {FS.include 77 Block8}
      {FS.include 78 Block8}

      Block9 = {FS.var.upperBound [1#81]}
      {FS.card Block9 9}
      {FS.include 61 Block9}
      {FS.include 62 Block9}
      {FS.include 63 Block9}
      {FS.include 70 Block9}
      {FS.include 71 Block9}
      {FS.include 72 Block9}
      {FS.include 79 Block9}
      {FS.include 80 Block9}
      {FS.include 81 Block9}

      {FS.card {FS.intersect {List.nth Sol 1} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 1} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 2} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 2} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 3} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 3} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 4} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 4} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 5} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 5} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 6} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 6} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 7} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 7} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 8} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 8} Block9} 1}

      {FS.card {FS.intersect {List.nth Sol 9} Row1} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row2} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row3} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row4} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row5} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row6} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row7} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row8} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Row9} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col1} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col2} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col3} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col4} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col5} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col6} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col7} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col8} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Col9} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block1} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block2} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block3} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block4} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block5} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block6} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block7} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block8} 1}
      {FS.card {FS.intersect {List.nth Sol 9} Block9} 1}
      
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 2}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 3}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 4}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 5}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 6}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 1} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 2} {List.nth Sol 3}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 4}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 5}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 6}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 2} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 3} {List.nth Sol 4}}
      {FS.disjoint {List.nth Sol 3} {List.nth Sol 5}}
      {FS.disjoint {List.nth Sol 3} {List.nth Sol 6}}
      {FS.disjoint {List.nth Sol 3} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 3} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 3} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 4} {List.nth Sol 5}}
      {FS.disjoint {List.nth Sol 4} {List.nth Sol 6}}
      {FS.disjoint {List.nth Sol 4} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 4} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 4} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 5} {List.nth Sol 6}}
      {FS.disjoint {List.nth Sol 5} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 5} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 5} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 6} {List.nth Sol 7}}
      {FS.disjoint {List.nth Sol 6} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 6} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 7} {List.nth Sol 8}}
      {FS.disjoint {List.nth Sol 7} {List.nth Sol 9}}

      {FS.disjoint {List.nth Sol 8} {List.nth Sol 9}} 
      
      {FS.distribute naive Sol}
   end
   
%%%%%%%%%%%%%%%%%%%%%%% procs for making output %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Takes a list of sets and outputs 9 lists of 9
proc {OutputSolution In ?Out}
   SetSize = 9
   SolList = {MakeList SetSize}
   {For 1 SetSize 1
    proc {$ S}
       {Nth SolList S} = {MakeList SetSize}
    end
    }
   C={NewCell 1} %% For incrementing through every position in the Sudoku matrix
in
   %% Nested Fors create 9 lists of 9 by iterating through the positions 1-81 and checking to see
   %% which set the number in that position should come from.
   {For 1 SetSize 1
    proc {$ X}               % for every set
       {For 1 SetSize 1      % for every position in that set
	proc {$ N}
	   {For 1 SetSize 1  % find out which solution set contains that postion and assign the corresponding number
	    proc {$ Y}
	       if {IsInSet {Nth In Y} @C} then {Nth {Nth SolList X} N} = Y end
	    end
	   }
	   C:=@C+1
	end
       }   
    end
   }
   Out = SolList
end

proc {IsInSet S M ?Out}
   C={NewCell false} in
   {FS.forAllIn S
    proc {$ X}
       if X==M then C:=true  end
    end
   }
   Out = @C
end
%%%%%%%%%%%%%%%%%%%%%%%%% End of output procs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{ExploreAll fun {$} {Sudoku Fiendish} end}
R={SearchOne fun {$} {Sudoku Fiendish} end}

%% SearchOne is returning a list of sets within a list and OutputSolution expects only a list of sets.
{Browse {OutputSolution R.1}}