Skip to content

Commit 8cc01b8

Browse files
committed
๐Ÿ‘‘ G4-2239
1 parent 7279aee commit 8cc01b8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

โ€Ž๐Ÿ‘‘ G4/2239.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sdoku = [list(input()) for _ in range(9)]
2+
3+
def backtraking(a, b):
4+
global sdoku
5+
if a >= 9:
6+
for i in sdoku:
7+
for j in i:
8+
print(j, end="")
9+
print()
10+
exit()
11+
if b == 9: return backtraking(a+1, 0)
12+
if sdoku[a][b] != '0': return backtraking(a, b+1)
13+
14+
for i in range(1, 10):
15+
if str(i) not in sdoku[a] and str(i) not in [sdoku[row][b] for row in range(9)]:
16+
if str(i) not in set(sum([sdoku[row][b//3*3:b//3*3+3] for row in range(9) if a//3*3 <= row < a//3*3+3], [])):
17+
sdoku[a][b] = str(i)
18+
backtraking(a, b+1)
19+
sdoku[a][b] = '0'
20+
21+
backtraking(0, 0)

0 commit comments

Comments
ย (0)