We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7279aee commit 8cc01b8Copy full SHA for 8cc01b8
โ๐ G4/2239.py
@@ -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