grid = [[0, 4, 8, 2, 0, 0 ,0, 0, 1],
[1, 0, 0, 3, 8, 4, 7, 2, 6],
[3, 0, 0, 7, 0, 1, 9, 4, 8],
[0, 7, 2, 6, 4, 5, 1, 8, 0],
[8, 0, 0, 0, 0, 2, 4, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 7],
[0, 8, 4, 0, 0, 0, 3, 0, 0],
[0, 8, 4, 0, 0, 0, 3, 0, 0],
[6, 0, 0, 4, 1, 0, 0, 0, 2],
[0, 0, 3, 0, 0, 0, 0, 7, 4]]
import numpy as np
print(np.matrix(grid))
def possible(y, x, n) :
global grid
for i in range(0, 9):
if grid[y][i] == n:
return False
for i in range(0, 9):
if grid[i][x] == n:
return False
x0 = (x//3)*3
y0 = (y//3)*3
for i in range(0,3) :
for j in range(0,3):
if grid[y0+i][x0+j] == n:
return False
return True
def solve():
global grid
for y in range(9):
for x in range(9):
if grid[y][x] == 0:
for n in range(1, 10):
if possible(y, x, n):
grid[y][x] = n
solve()
grid[y][x] = 0
return
print(np.matrix(grid))
input('more?')
hello. I am a beginner. This is just my third day of using python. I am also new to this forum. I decided to do some sudoku solver and followed someone on youtube. And learn the thinking process behind it. I followed it through and through. But got different results. the output is printing the grid. by it seem the function solve() is not.
I hope I am not wasting your time. I am just a beginner that wants to learn.( I am using psycharm, if that counts)
Thank you.