Program SoDoku;
{William Wheeless
February 2, 2006
Intermediate 5
Enloe High School
Potter
ACSL 2}
USES CRT;
TYPE
Grid=Array[1..9,1..9] of Integer;
VAR
Puzzle:Grid;
Procedure Input(VAR
Puzzle:Grid);
VAR
X,Y:Integer;
Begin
CLRSCR;
Writeln('Please input the numbers in each row, pressing enter
after each number.');
For X:=1 to 9 do
For Y:=1 to 9 do
Begin
Gotoxy(2*Y,X+1);
Read(Puzzle[X,Y]);
If (Y=9) then
Writeln;
End;
End;
Procedure Numbers(VAR
Puzzle:Grid);
VAR
X,Y,Z:Integer;
Xcoord,Ycoord,Upperrow,Lowerrow,Uppercol,Lowercol:Integer;
Nine:Array[1..9] of Boolean;
Count:Integer;
Begin
Writeln;
Writeln('Input the coordinates that you want to reveal. After
each input, the program');
Writeln('will tell you which number goes in that box.');
For X:=1 to 5 do
Begin
Write('Row',X,': ');
Readln(xcoord);
Write('Column',X,': ');
Readln(Ycoord);
If (Xcoord mod 3 = 1) then
Begin
Lowerrow:=Xcoord;
Upperrow:=Xcoord+2;
End
Else if (Xcoord mod 3 = 2) then
Begin
Lowerrow:=Xcoord-1;
Upperrow:=Xcoord+1;
End
Else
Begin
Lowerrow:=Xcoord-2;
Upperrow:=Xcoord;
End;
If (Ycoord mod 3
= 1) then
Begin
Lowercol:=Ycoord;
Uppercol:=Ycoord+2;
End
Else if (Ycoord mod 3 = 2) then
Begin
Lowercol:=Ycoord-1;
Uppercol:=Ycoord+1;
End
Else
Begin
Lowercol:=Ycoord-2;
Uppercol:=Ycoord;
End;
For Y:=1 to 9 do
Nine[Y]:=False;
For Y:=1 to 9 do
Begin
If NOT(Puzzle[Xcoord,Y]=0) then
Nine[Puzzle[Xcoord,Y]]:=True;
If NOT(Puzzle[Y,Ycoord]=0) then
Nine[Puzzle[Y,Ycoord]]:=True;
End;
For Y:=Lowerrow to Upperrow do
For Z:=Lowercol to Uppercol do
If NOT(Puzzle[Y,Z]=0) then
Nine[Puzzle[Y,Z]]:=True;
Count:=0;
For Y:=1 to 9 do
If (Nine[Y]=False) then
Count:=Count+1;
If (Count=1) then
Begin
Z:=0;
Repeat
Z:=z+1;
Until (Nine[Z]=False);
Puzzle[Xcoord,Ycoord]:=Z;
End;
Writeln;
Writeln(Z,' is in box ',Xcoord,',',Ycoord,'.');
End;
Readln;
End;
Begin
Input(Puzzle);
Numbers(Puzzle);
Readln;
End.