Created
September 9, 2022 11:56
-
-
Save cazeip/bed7087160bba4251b68e0d3433f5ae7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Résolveur de Sudoku | |
grille = [ | |
[0,0,0,0,4,0,0,7,0], | |
[0,0,6,0,2,0,0,0,0], | |
[5,0,0,7,0,6,0,0,9], | |
[0,0,5,3,0,1,0,2,0], | |
[0,0,0,0,6,0,0,0,0], | |
[9,0,0,0,0,0,8,0,0], | |
[0,3,0,0,0,0,0,0,2], | |
[0,0,0,4,0,0,0,0,0], | |
[0,0,1,5,0,7,0,3,0], | |
] | |
def verification(y, x, n): | |
#Ligne | |
for i in range(9): | |
if grille[y][i] == n: | |
return False | |
#Colone | |
for i in range(9): | |
if grille[i][x] == n: | |
return False | |
#Case | |
dx = (x // 3) * 3 | |
dy = (y // 3) * 3 | |
for i in range(dy, dy + 3): | |
for j in range(dx, dx + 3): | |
if grille[i][j] == n: | |
return False | |
return True | |
def resoudre(): | |
for y in range(9): | |
for x in range(9): | |
if grille[y][x] == 0: | |
for n in range(1, 10): | |
if verification(y, x, n): | |
grille[y][x] = n | |
if resoudre(): | |
return True | |
else: | |
grille[y][x] = 0 | |
return False | |
for y in range(9): | |
print(grille[y]) | |
return True | |
resoudre() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment