procedure TForm1.Button1Click(Sender: TObject);
var i,j,k,l,m,sq:integer;
begin
for i:= 1 to 9 do //Einlesen der Matrix aus dem Stringgrid
begin
for j:=1 to 9 do
begin
if not ((sg.cells[i-1,j-1]) = '') then mat[j,i] := strtoint(sg.cells[i-1,j-1]);
if ((sg.cells[i-1,j-1]) = '') then mat[j,i] := 0;
end;
end;
//=========================Kernalgorithmus
//===========LÖSUNGSTEIL
for i:= 1 to 9 do
begin
for j:= 1 to 9 do //Zählschleifen für jede einzelne Zelle
begin
for k:= 1 to 9 do //Alle Zahlen in der gleichen Reihe in Vektor schreiben
begin
if ((mat[i,k]<>0) and (k<>j)) then sol[i,j,(mat[i,k])] := mat[i,k];
end;
for k:= 1 to 9 do //Alle Zahlen in der gleichen Spalte in den gleichen Vektor schreiben
begin
if ((mat[k,j]<>0) and (k<>i)) then sol[i,j,(mat[k,j])] := mat[k,j];
end;
//Alle Zahlen aus gleichen 3x3 Quadrat mit in den Vektor schreiben
//Dazu zuerst: Fallunterscheidung in die 9 Quadrate
if ((i<4) and (j<4)) then sq := 1;
if ((i<4) and (j>3) and (j<7)) then sq := 2;
if ((i<4) and (j>6)) then sq := 3;
if ((i>3) and (i<7) and (j<4)) then sq := 4;
if ((i>3) and (i<7) and (j>3) and (j<7))then sq := 5;
if ((i>3) and (i<7) and (j>6)) then sq := 6;
if ((i>6) and (j<4)) then sq := 7;
if ((i>6) and (j>3) and (j<7)) then sq := 8;
if ((i>6) and (j>6)) then sq := 9;
//Und dann dazuschreiben der Zahlen aus dem zugehörigen 3x3 Quadrat
for k := 1 to 3 do
begin
for l := 1 to 3 do
begin
if sq=1 then begin if ((mat[k,l]<>0) and ((k<>i) and (l<>j))) then sol[i,j,(mat[k,l])] := mat[k,l]; end;
if sq=2 then begin if ((mat[k,l+3]<>0) and ((k<>i) and (l+3<>j))) then sol[i,j,(mat[k,l+3])] := mat[k,l+3]; end;
if sq=3 then begin if ((mat[k,l+6]<>0) and ((k<>i) and (l+6<>j))) then sol[i,j,(mat[k,l+6])] := mat[k,l+6]; end;
if sq=4 then begin if ((mat[k+3,l]<>0) and ((k+3<>i) and (l<>j))) then sol[i,j,(mat[k+3,l])] := mat[k+3,l]; end;
if sq=5 then begin if ((mat[k+3,l+3]<>0) and ((k+3<>i) and (l+3<>j))) then sol[i,j,(mat[k+3,l+3])] := mat[k+3,l+3]; end;
if sq=6 then begin if ((mat[k+3,l+6]<>0) and ((k+3<>i) and (l+6<>j))) then sol[i,j,(mat[k+3,l+6])] := mat[k+3,l+6]; end;
if sq=7 then begin if ((mat[k+6,l]<>0) and ((k+6<>i) and (l<>j))) then sol[i,j,(mat[k+6,l])] := mat[k+6,l]; end;
if sq=8 then begin if ((mat[k+6,l+3]<>0) and ((k+6<>i) and (l+3<>j))) then sol[i,j,(mat[k+6,l+3])] := mat[k+6,l+3]; end;
if sq=9 then begin if ((mat[k+6,l+6]<>0) and ((k+6<>i) and (l+6<>j))) then sol[i,j,(mat[k+6,l+6])] := mat[k+6,l+6]; end;
end;
end;
end;
end;
.....
.....