def test(): t0 = time.clock() for example in examples: print() print(13 * ' ', example) print('%6.4f sec: %s ' % timer.timedcall(faster_solve, example)) print('%6.4f tot.' % (time.clock() - t0))
def main(): puzzle = "ODD + ODD == EVEN" print(timedcall(solve, puzzle))
def main(): puzzle = "ODD + ODD == EVEN" # no big difference vs. crypto # 0.44s vs. 0.59s print(timedcall(solve, puzzle))
def zebra_puzzle(): houses = [first, _, middle, _, _] = [1, 2, 3, 4, 5] orderings = list(itertools.permutations(houses)) return [(WATER, ZEBRA) for(red, green, ivory, yellow, blue) in orderings if imright(green, ivory) # 6 for (Englishman, Spaniard, Ukranian, Japanese, Norwegian) in orderings if Englishman is red # 2 if Norwegian is first # 10 if nextto(Norwegian, blue) # 15 for (cofee, tea, milk, oj, WATER) in orderings if cofee is green # 4 if Ukranian is tea # 5 if milk is middle # 9 for (OldGold, Kools, Chesterfields, LuckyStrike, Parliaments) in orderings if Kools is yellow # 8 if LuckyStrike is oj # 13 if Japanese is Parliaments # 14 for (dog, snails, fox, horse, ZEBRA) in orderings if Spaniard is dog # 3 if OldGold is snails # 7 if nextto(Chesterfields, fox) if nextto(Kools, horse)] print timer.timedcall(zebra_puzzle)
def nextto(h1, h2): "Two houses are next to each other if they differ by 1." return abs(h1 - h2) == 1 def zebra_puzzle(): houses = [first, _, middle, _, _] = [1, 2, 3, 4, 5] orderings = list(itertools.permutations(houses)) return [ (WATER, ZEBRA) for (red, green, ivory, yellow, blue) in orderings if imright(green, ivory) # 6 for (Englishman, Spaniard, Ukranian, Japanese, Norwegian) in orderings if Englishman is red # 2 if Norwegian is first # 10 if nextto(Norwegian, blue) # 15 for (cofee, tea, milk, oj, WATER) in orderings if cofee is green # 4 if Ukranian is tea # 5 if milk is middle # 9 for (OldGold, Kools, Chesterfields, LuckyStrike, Parliaments) in orderings if Kools is yellow # 8 if LuckyStrike is oj # 13 if Japanese is Parliaments # 14 for (dog, snails, fox, horse, ZEBRA) in orderings if Spaniard is dog # 3 if OldGold is snails # 7 if nextto(Chesterfields, fox) if nextto(Kools, horse) ] print timer.timedcall(zebra_puzzle)