Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Sudoku Solver by TovarischZhukov
DIGITS = set(range(1,10))
def getNums(grid,i,j):
ret=set(grid[i])
for k in range(len(grid)):
ret.add(grid[k][j])
posi=i/3;posj=j/3
for i in range(posi*3,posi*3+3):
for j in range(posj*3,posj*3+3):
ret.add(grid[i][j])
return DIGITS.difference(ret)
def checkio(grid,sti=0):
find=False
for i in range(sti,len(grid)):
for j in range(len(grid)):
if not grid[i][j]:
find=True
for num in getNums(grid,i,j):
n_grid=grid[:]
n_grid[i]=n_grid[i][:]
n_grid[i][j]=num
r=checkio(n_grid,i)
if r:return r
else: return None
if not find: return grid
Feb. 11, 2016