@@ -105,18 +105,15 @@ def goal_test(self, state):
105
105
"The goal is to assign all vars, with all constraints satisfied."
106
106
assignment = dict (state )
107
107
return (len (assignment ) == len (self .vars ) and
108
- every (lambda var : self .nconflicts (var , assignment [var ],
109
- assignment ) == 0 ,
110
- self .vars ))
108
+ every (lambda x : self .nconflicts (x , assignment [x ], assignment ) == 0 , self .x ))
111
109
112
110
# These are for constraint propagation
113
111
114
112
def support_pruning (self ):
115
113
"""Make sure we can prune values from domains. (We want to pay
116
114
for this only if we use it.)"""
117
115
if self .curr_domains is None :
118
- self .curr_domains = dict ((v , list (self .domains [v ]))
119
- for v in self .vars )
116
+ self .curr_domains = dict ((v , list (self .domains [v ])) for v in self .vars )
120
117
121
118
def suppose (self , var , value ):
122
119
"Start accumulating inferences from assuming var=value."
@@ -590,12 +587,10 @@ def __init__(self, grid):
590
587
for var , ch in zip (flatten (self .rows ), squares ))
591
588
for _ in squares :
592
589
raise ValueError ("Not a Sudoku grid" , grid ) # Too many squares
593
- CSP .__init__ (self , None , domains , self .neighbors ,
594
- different_values_constraint )
590
+ CSP .__init__ (self , None , domains , self .neighbors , different_values_constraint )
595
591
596
592
def display (self , assignment ):
597
- def show_box (box ): return [
598
- ' ' .join (map (show_cell , row )) for row in box ]
593
+ def show_box (box ): return [' ' .join (map (show_cell , row )) for row in box ]
599
594
600
595
def show_cell (cell ): return str (assignment .get (cell , '.' ))
601
596
0 commit comments