Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Bruteforce solution in Clear category for Sudoku Solver by altarfinch
from copy import deepcopy
# Return the solution of the sudoku.
def checkio(g):
empty_cells = [(i,j) for i,r in enumerate(g) for j,e in enumerate(r) if e==0]
if not empty_cells: return g
i, j = empty_cells[0]
pos = set(range(1,10)) - set(g[i]) - set(zip(*g)[j]) \
- {g[i/3*3+di][j/3*3+dj] for di in range(3) for dj in range(3)}
for n in pos:
ng = deepcopy(g)
ng[i][j] = n
r = checkio(ng)
if r: return r
return []
March 20, 2015