Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sudoku Solver solution in Uncategorized category for Sudoku Solver by capback250
def checkio(sudoku):
i, j, backtrack = 0, 0, []
while i < 9 and j < 9:
if not sudoku[i][j]:
v = squares(sudoku, i, j)
while not v:
i, j, v, sudoku[i][j] = backtrack.pop()
sudoku[i][j] = v.pop()
backtrack.append((i, j, v, 0))
i, j = i + (j + 1) // 9, (j + 1) % 9
return sudoku
def squares(sudoku, i, j):
c = []
n = {}
for z in [0,3,6]:
for x in range(0, 8, 3):
tepm = []
for y in range(3):
tepm.extend(sudoku[y+z][x:x+3])
c.append(tepm)
for key, row in enumerate(c):
n[key] = set(row)
return list(set(range(1,10))-n[positioner(i, j)]-linear(sudoku, i, j))
def linear(sudoku, i, j):
hor = []
vert = []
for k in range(9):
hor.append(sudoku[i][k])
vert.append(sudoku[k][j])
return set(hor+vert)
def positioner(i, j):
if i < 3 and j < 3:
return 0
if i < 3 and 3 <= j < 6:
return 1
if i < 3 and 6 <= j < 9:
return 2
if 3 <= i < 6 and j < 3:
return 3
if 3 <= i < 6 and 3 <= j < 6:
return 4
if 3 <= i < 6 and 6 <= j < 9:
return 5
if 6 <= i < 9 and j < 3:
return 6
if 6 <= i < 9 and 3 <= j < 6:
return 7
if 6 <= i < 9 and 6 <= j < 9:
return 8
Nov. 13, 2015