fork download
  1. declare
  2. proc {Sudoku P ?Grid}
  3. %% Creo la lista di 9 elementi, tutti UNBOUND inizialmente
  4. Grid = {List.make 9}
  5. %% Popola ogni elemento di Grid con un'altra lista, aventi 9 elementi con valore 1#9 (range di valori ammissibili del sudoku)
  6. {List.forAll Grid proc {$ Row} Row = {FD.list 9 1#9} end}
  7. %% Vincoli RIGA
  8. for I in 1..9 do
  9. {FD.distinct {Nth Grid I}} %% Nth estrae l'iesimo elemento da Grid, la distinct verifica che non si ripetano elementi
  10. end
  11. %% Vincoli COLONNA
  12. for J in 1..9 do
  13. {FD.distinct {List.map Grid fun {$ Row}
  14. {Nth Row J}
  15. end
  16. }
  17. }
  18. end
  19. %% Vincoli BLOCCO
  20. for BI in 0..2 do
  21. for BJ in 0..2 do
  22. Block = for I in 1..3 collect:Collect do
  23. for J in 1..3 do
  24. {Collect {Nth {Nth Grid (3*BI+I)} (3*BJ+J)}}
  25. end
  26. end
  27. in
  28. {FD.distinct Block}
  29. end
  30. end
  31. %% Vincoli sui Valori
  32. {List.forAllInd P
  33. proc {$ Y R}
  34. Row = {Nth Grid Y}
  35. in
  36. {List.forAllInd R
  37. proc {$ X I}
  38. if {Not {IsFree I}} then
  39. {Nth Row X} :: I
  40. end
  41. end
  42. }
  43. end
  44. }
  45. {FD.distribute ff {Flatten Grid}} %% la FD accetta solo LISTE semplici, e non liste di liste, quindi uso la Flatten su Grid
  46. end
  47. declare
  48. Puzzle=[
  49. [_ _ _ 6 _ _ _ _ 4]
  50. [8 _ _ _ _ _ _ 7 _]
  51. [_ _ 5 _ _ 9 _ _ 3]
  52. [_ _ _ 8 _ _ 2 _ 1]
  53. [_ 9 _ _ _ _ _ 6 _]
  54. [4 _ 6 _ _ 3 _ _ _]
  55. [1 _ _ 2 _ _ 5 _ _]
  56. [_ 7 _ _ _ _ _ _ 8]
  57. [3 _ _ _ _ 4 _ _ _]
  58. ]
  59. {Browse {Search.base.one proc{$ Sol} {Sudoku Puzzle Sol} end}}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Mozart Compiler 1.4.0 (20080704) playing Oz 3

%%% feeding file prog.oz

%********************* binding analysis error *******************
%**
%** variable FD not introduced
%**
%** in file "./prog.oz", line 6, column 41

%********************* binding analysis error *******************
%**
%** variable FD not introduced
%**
%** in file "./prog.oz", line 9, column 7

%********************* binding analysis error *******************
%**
%** variable FD not introduced
%**
%** in file "./prog.oz", line 13, column 7

%********************* binding analysis error *******************
%**
%** variable FD not introduced
%**
%** in file "./prog.oz", line 28, column 3

%********************* binding analysis error *******************
%**
%** variable FD not introduced
%**
%** in file "./prog.oz", line 45, column 4
%** ------------------ rejected (5 errors)
stdout
Standard output is empty