Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
Delphi 10.4 Sydney
|
AW: Sudoku Array of Array vergleichen
20. Nov 2011, 17:43
Für die Sudoku Fans:
Delphi-Quellcode:
function BlockToRowCol(Block, Index: integer): TPoint;
begin
// Block 0..8, Index 0..8
// Result.X = Row 0..8, Result.Y = Col 0..8
Result.X:= (Block div 3) * 3 + Index div 3;
Result.Y:= (Block mod 3) * 3 + (Index + 3) mod 3;
end;
function RowColToBlock(Row, Col: integer): TPoint;
begin
// Row 0..8, Col 0..8
// Result.X = Block 0..8, Result.Y = Index 0..8
Result.X:= Row div 3 mod 3 * 3 + Col div 3 mod 3;
Result.Y:= Row mod 3 * 3 + Col mod 3;
end;
function IndexToRowCol(K: integer): TPoint;
begin
// K 0..80
// Result.X = Row 0..8, Result.Y = Col 0..8
Result.X:= K div 9;
Result.Y:= K - Result.X * 9;
end;
function RowColToIndex(Row, Col: integer): integer;
begin
// Row 0..8, Col 0..8
// Result = K 0..80
Result:= Row * 9 + Col;
end;
Geändert von Bjoerk (20. Nov 2011 um 17:58 Uhr)
Grund: TPoint
|
|
Zitat
|