Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
71
Task/Sudoku/XPL0/sudoku.xpl0
Normal file
71
Task/Sudoku/XPL0/sudoku.xpl0
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
code ChOut=8, CrLf=9, IntOut=11, Text=12;
|
||||
|
||||
proc Show(X);
|
||||
char X;
|
||||
int I, J;
|
||||
[for I:= 0 to 8 do
|
||||
[if rem(I/3) = 0 then CrLf(0);
|
||||
for J:= 0 to 8 do
|
||||
[if rem(J/3) = 0 then ChOut(0, ^ );
|
||||
ChOut(0, ^ ); IntOut(0, X(0));
|
||||
X:= X+1;
|
||||
];
|
||||
CrLf(0);
|
||||
];
|
||||
];
|
||||
|
||||
func TryCell(X, Pos);
|
||||
char X;
|
||||
int Pos;
|
||||
int Row, Col, I, J, Used;
|
||||
[Row:= Pos/9;
|
||||
Col:= rem(0);
|
||||
Used:= 0;
|
||||
|
||||
if Pos = 81 then return true;
|
||||
if X(Pos) then return TryCell(X, Pos+1);
|
||||
|
||||
for I:= 0 to 8 do Used:= Used ! 1 << (X(I*9+Col)-1);
|
||||
for J:= 0 to 8 do Used:= Used ! 1 << (X(Row*9+J)-1);
|
||||
|
||||
Row:= Row/3*3;
|
||||
Col:= Col/3*3;
|
||||
for I:= Row to Row+2 do
|
||||
for J:= Col to Col+2 do
|
||||
Used:= Used ! 1 << (X(I*9+J)-1);
|
||||
|
||||
for I:= 1 to 9 do
|
||||
[X(Pos):= I;
|
||||
if (Used&1)=0 & TryCell(X, Pos+1) then return true;
|
||||
Used:= Used>>1;
|
||||
];
|
||||
X(Pos):= 0;
|
||||
return false;
|
||||
];
|
||||
|
||||
proc Solve(S);
|
||||
char S;
|
||||
int I, J, C;
|
||||
char X(81);
|
||||
[J:= 0;
|
||||
for I:= 0 to 80 do
|
||||
[repeat C:= S(J);
|
||||
J:= J+1;
|
||||
until C>=^1 & C<=^9 ! C=^.;
|
||||
X(I):= if C=^. then 0 else C-^0;
|
||||
];
|
||||
|
||||
if TryCell(X, 0) then Show(X)
|
||||
else Text(0, "No solution");
|
||||
];
|
||||
|
||||
[Solve("394 ..2 67.
|
||||
... 3.. 4..
|
||||
5.. 69. .2.
|
||||
.45 ... 9..
|
||||
6.. ... ..7
|
||||
..7 ... 58.
|
||||
.1. .67 ..8
|
||||
..9 ..8 ...
|
||||
.26 4.. 735 ");
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue