Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -9,7 +9,7 @@ type
|
|||
|
||||
function CheckValidity(val: Integer; x: Integer; y: Integer): Boolean;
|
||||
function ToString: string; reintroduce;
|
||||
procedure PlaceNumber(pos: Integer);
|
||||
function PlaceNumber(pos: Integer): Boolean;
|
||||
public
|
||||
constructor Create(s: string);
|
||||
|
||||
|
|
@ -79,15 +79,19 @@ begin
|
|||
Result := sb;
|
||||
end;
|
||||
|
||||
procedure TSudokuSolver.PlaceNumber(pos: Integer);
|
||||
function TSudokuSolver.PlaceNumber(pos: Integer): Boolean;
|
||||
var
|
||||
n: Integer;
|
||||
begin
|
||||
Result := False;
|
||||
if Pos = 81 then
|
||||
raise Exception.Create('Finished!');
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
if FGrid[pos] > 0 then
|
||||
begin
|
||||
PlaceNumber(Succ(pos));
|
||||
Result := PlaceNumber(Succ(pos));
|
||||
Exit;
|
||||
end;
|
||||
for n := 1 to 9 do
|
||||
|
|
@ -95,8 +99,9 @@ begin
|
|||
if CheckValidity(n, pos mod 9, pos div 9) then
|
||||
begin
|
||||
FGrid[pos] := n;
|
||||
PlaceNumber(Succ(pos));
|
||||
FGrid[pos] := 0;
|
||||
Result := PlaceNumber(Succ(pos));
|
||||
if not Result then
|
||||
FGrid[pos] := 0;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
|
@ -112,11 +117,9 @@ end;
|
|||
|
||||
procedure TSudokuSolver.Solve;
|
||||
begin
|
||||
try
|
||||
PlaceNumber(0);
|
||||
if not PlaceNumber(0) then
|
||||
ShowMessage('Unsolvable');
|
||||
except
|
||||
ShowMessage((ExceptObject as Exception).Message);
|
||||
ShowMessage(ToString);
|
||||
else
|
||||
ShowMessage('Solved!');
|
||||
end;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue