# -*- Mode: Python -*- from constraint import * from pprint import pprint as pp # a problem from www.logic-puzzles.org # 1. The baker who made gingerbread cookies is famous for the song A Single Kiss. # 2. The singer known for All By Myself received a larger reward than Raquel. # 3. The baker who made peanut butter cookies is not Bryce. # 4. The baker who made oatmeal raisin cookies doesn't sing One More Time or Summer Blues. # 5. Of Bryce and the baker who made gingerbread cookies, one earned the $980 reward and the other earned the $1240 reward. # 6. Wendy was rewarded less than the singer known for One More Time. # 7. The singer known for All By Myself is Riley. # 8. Either the one who received the $1240 reward or the one who received the $1660 reward is famous for the song A Single Kiss. # BRIW = bryce raquel riley wendy # kmts = a single kiss, all by myself, one more time, summer blues # cgop = chocolate chip, gingerbread, oatmeal raisin, peanut butter rewards = [370,980,1240,1660] p = Problem() p.addVariables ("BRIWkmtscgop", rewards) p.addConstraint (AllDifferentConstraint(), "BRIW") p.addConstraint (AllDifferentConstraint(), "kmts") p.addConstraint (AllDifferentConstraint(), "cgop") p.addConstraint (lambda g,k: g==k, 'gk') p.addConstraint (lambda m,R: m>R, 'mR') p.addConstraint (lambda p,B: p!=B, 'pB') p.addConstraint (lambda o,t,s: o != t and o != s, 'ots') p.addConstraint (lambda B,g: (B==980 and g==1240) or (B==1240 and g==980), 'Bg') p.addConstraint (lambda W,t: W < t, "Wt") p.addConstraint (lambda I,m: I == m, "Im") p.addConstraint (lambda k: k == 1240 or k == 1660, "k") pp (p.getSolutions())