def make_sudoku_CSP():
 rows = range(9)
 cols = range(9)
 vars = cross(rows, cols)
 domains = defaultdict((lambda : range(1, 10)))
 triples = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
 unitlist = (([cross(rows, [c]) for c in cols] + [cross([r], cols) for r in rows]) + [cross(rs, cs) for rs in triples for cs in triples])
 neighbors = defaultdict((lambda : set([])))
 for unit in unitlist:
  for cell in unit:
   neighbors[cell].update(unit)
   neighbors[cell].remove(cell)
 return SudokuCSP(vars=vars, domains=domains, neighbors=neighbors, binary_constraint=unequal_vals_constraint)

def make_sudoku_CSP ( ) : rows = range ( 9 ) cols = range ( 9 ) vars = cross ( rows , cols ) domains = defaultdict ( ( lambda : range ( 1 , 10 ) ) ) triples = [ [ 0 , 1 , 2 ] , [ 3 , 4 , 5 ] , [ 6 , 7 , 8 ] ] unitlist = ( ( [ cross ( rows , [ c ] ) for c in cols ] + [ cross ( [ r ] , cols ) for r in rows ] ) + [ cross ( rs , cs ) for rs in triples for cs in triples ] ) neighbors = defaultdict ( ( lambda : set ( [ ] ) ) ) for unit in unitlist : for cell in unit : neighbors [ cell ] . update ( unit ) neighbors [ cell ] . remove ( cell ) return SudokuCSP ( vars = vars , domains = domains , neighbors = neighbors , binary_constraint = unequal_vals_constraint )
a regular 9x9 sudoku puzzle .