sudoku.py gelöscht

This commit is contained in:
klaas 2024-09-24 16:08:16 +02:00
parent 9b07fc4dfa
commit 2416adaa52
1 changed files with 0 additions and 57 deletions

View File

@ -1,57 +0,0 @@
start = [[0, 8, 0, 0, 2, 0, 5, 6, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 7],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 5, 0, 0, 9, 0, 4, 0, 8],
[0, 0, 7, 8, 0, 0, 0, 0, 3],
[0, 9, 0, 0, 1, 0, 0, 5, 0],
[2, 0, 4, 0, 0, 0, 8, 0, 0],
[0, 6, 0, 0, 8, 5, 0, 0, 0],
[0, 0, 0, 2, 0, 0, 1, 0, 0]]
def isfine(feld, x, y):
for (int yi = 0; yi < 9; yi++):
if (yi != y && feld[x][yi] == feld[x][y]):
return false;
for (int xi = 0; xi < 9; xi++):
if (xi != x && feld[xi][y] == feld[x][y]):
return false;
x1 = (x / 3) * 3;
y1 = (y / 3) * 3;
for (int xk = x1; xk < x1 + 3; xk++):
for (int yk = y1; yk < y1 + 3; yk++):
if ((xk!=x || yk!=y) && feld[xk][yk]==feld[x][y]):
return false;
return true;
}
def nextone(feld, x, y):
if (y == 9):
y = 0;
x++;
if (x == 9):
return true;
if (feld[x][y] > 0):
if (!isfine(feld, x, y)) return false;
return nextone(feld, x, y + 1);
else:
for (feld[x][y] = 1; feld[x][y] <= 9; feld[x][y]++):
if (!isfine(feld, x, y)) continue;
if (nextone(feld, x, y + 1)) return true;
feld[x][y] = 0;
return false;
tstart = clock();
if (nextone(start, 0, 0)):
for (int x = 0; x < 9; x++):
for (int y = 0; y < 9; y++):
cout << start[x][y];
cout << endl;
else:
print("Unmöglich!");
time1=clock();
print(tstart." - " .time1."*".CLOCKS_PER_SEC)