-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsudoku.py
More file actions
39 lines (36 loc) · 1.45 KB
/
sudoku.py
File metadata and controls
39 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
plansza = [[4, 1, 0, 3, 0, 0, 7, 6, 0],
[0, 9, 3, 0, 7, 0, 4, 0, 1],
[2, 0, 0, 1, 4, 0, 0, 8, 3],
[9, 5, 8, 0, 0, 0, 0, 0, 7],
[3, 4, 0, 0, 0, 0, 0, 1, 0],
[0, 7, 2, 8, 9, 3, 5, 4, 0],
[0, 8, 0, 2, 0, 0, 3, 7, 4],
[0, 0, 4, 0, 0, 0, 1, 9, 5],
[0, 0, 0, 0, 5, 0, 6, 0, 0]]
def start_check():
while True:
made_changes = False
for i, line in enumerate(plansza):
for j, number in enumerate(line):
if number == 0:
lista = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for lista_num in line:
if lista_num in lista:
lista.remove(lista_num)
for s in range(9):
if plansza[s][j] in lista:
lista.remove(plansza[s][j])
line_start = i - i % 3
column_start = j - j % 3
for m in range(3):
for r in range(3):
if plansza[line_start + m][column_start + r] in lista:
lista.remove(plansza[line_start + m][column_start + r])
if len(lista) == 1:
plansza[i][j] = lista[0]
made_changes = True
if not made_changes:
break
start_check()
for line in plansza:
print(line)