Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9b0efa

Browse files
committed
Made Sudoku example work in Python 2.5.
1 parent da79112 commit c9b0efa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

csp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,12 @@ class Sudoku(CSP):
486486
bgrid = [[[[Cell() for x in R3] for y in R3] for bx in R3] for by in R3]
487487
boxes = flatten([map(flatten, brow) for brow in bgrid])
488488
rows = flatten([map(flatten, zip(*brow)) for brow in bgrid])
489-
units = map(set, boxes + rows + zip(*rows))
490-
neighbors = dict([(v, set.union(*[u for u in units if v in u]) - set([v]))
491-
for v in flatten(rows)])
489+
cols = zip(*rows)
490+
491+
neighbors = dict([(v, set()) for v in flatten(rows)])
492+
for unit in map(set, boxes + rows + cols):
493+
for v in unit:
494+
neighbors[v].update(unit - set([v]))
492495

493496
def __init__(self, grid):
494497
"""Build a Sudoku problem from a string representing the grid:

0 commit comments

Comments
 (0)