Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions 20 csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def conflict(var2):
def display(self, assignment):
"Show a human-readable representation of the CSP."
# Subclasses can print in a prettier way, or display with a GUI
print 'CSP:', self, 'with assignment:', assignment
print ('CSP:', self, 'with assignment:', assignment)

## These methods are for the tree- and graph-search interface:

Expand Down Expand Up @@ -460,13 +460,13 @@ def display(self, assignment):
if assignment.get(var,'') == val: ch = 'Q'
elif (var+val) % 2 == 0: ch = '.'
else: ch = '-'
print ch,
print ' ',
print (ch),
print (' ',)
for var in range(n):
if assignment.get(var,'') == val: ch = '*'
else: ch = ' '
print str(self.nconflicts(var, val, assignment))+ch,
print
print ((str(self.nconflicts(var, val, assignment))+ch),)
print ()

#______________________________________________________________________________
# Sudoku
Expand Down Expand Up @@ -541,8 +541,8 @@ def display(self, assignment):
def show_box(box): return [' '.join(map(show_cell, row)) for row in box]
def show_cell(cell): return str(assignment.get(cell, '.'))
def abut(lines1, lines2): return map(' | '.join, zip(lines1, lines2))
print '\n------+-------+------\n'.join(
'\n'.join(reduce(abut, map(show_box, brow))) for brow in self.bgrid)
print ('\n------+-------+------\n'.join(
'\n'.join(reduce(abut, map(show_box, brow))) for brow in self.bgrid))

#______________________________________________________________________________
# The Zebra Puzzle
Expand Down Expand Up @@ -599,10 +599,10 @@ def solve_zebra(algorithm=min_conflicts, **args):
z = Zebra()
ans = algorithm(z, **args)
for h in range(1, 6):
print 'House', h,
print ('House', h,)
for (var, val) in ans.items():
if val == h: print var,
print
if val == h: print (var,)
print ()
return ans['Zebra'], ans['Water'], z.nassigns, ans


Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.