Zebra puzzle: Difference between revisions

Content deleted Content added
Dukeiizu (talk | contribs)
Dukeiizu (talk | contribs)
Line 5,316:
Drink = ["Tea", "Coffee", "Milk", "Orangejuice", "Water" ]
 
# add variables: house numbers 1 to 5
problem.addVariables(Nation, range(1,5+1))
problem.addVariables(Color, range(1,5+1))
Line 5,323:
problem.addVariables(Drink, range(1,5+1))
 
# add constraint: the values in each list are exclusive
problem.addConstraint(AllDifferentConstraint(), Nation)
problem.addConstraint(AllDifferentConstraint(), Color)
Line 5,329 ⟶ 5,330:
problem.addConstraint(AllDifferentConstraint(), Drink)
 
# add constraint: actual constraints
problem.addConstraint(lambda a, b: a == b, ["Englishman", "Red" ])
problem.addConstraint(lambda a, b: a == b, ["Spaniard", "Dog" ])
Line 5,344 ⟶ 5,346:
problem.addConstraint(lambda a, b: a == b - 1 or a == b + 1, ["Norwegian", "Blue" ])
 
# get solution
sol = problem.getSolution()
 
# print the answers
nation = ["Nation" if i == 0 else "" for i in range(6)]
color = ["Color" if i == 0 else "" for i in range(6)]