

Einstein's election riddle: are you in the two per cent that can solve it? - samaysharma
http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/04/einsteins-election-riddle-are-you-in-the-two-per-cent-that-can-solve-it

======
todd8
I came up with the following approach in Python last time I saw this puzzle
here (see:
[https://news.ycombinator.com/item?id=7734998](https://news.ycombinator.com/item?id=7734998))

    
    
        from itertools import permutations as perms
        houses = range(5)             # numbered 0, 1, 2, 3, 4
        for david, ed, nick, nicola, nigel in perms(houses):
            if nick != 0: continue                          # by 9.
            for tartan, paisley, gingham, striped, polka_dot in perms(houses):
                if nicola != tartan: continue               # by 1.
                if paisley != gingham - 1: continue         # by 4. 
                if nick not in [polka_dot-1, polka_dot+1]: continue    # by 14.
                for mochaccino, flat_white, dbl_espresso, chai, decaf in perms(houses):
                    if dbl_espresso != 2: continue          # by 8.
                    if david != mochaccino: continue        # by 3.
                    if paisley != flat_white: continue      # by 5.
                    for car, bike, train, foot, plane in perms(houses):
                        if striped != bike: continue        # by 7.
                        if plane != chai: continue          # by 12. 
                        if nigel != foot: continue          # by 13.
                        if train not in [decaf-1, decaf+1]: continue
                        for guinea_pig, squirrel, pitbull, badger, fish in perms(houses):
                            if ed != guinea_pig: continue   # by 2.
                            if car != squirrel: continue    # by 6. 
                            if badger not in [bike-1, bike+1]: continue  # by 11.
                            if train not in [pitbull-1, pitbull+1]: continue  # by 10.
    
                            person =  {david: "David", ed: "Ed", nick: "Nick",
                                     nicola: "Nicola", nigel: "Nigel"}
                            print "{} owns the fish".format(person[fish])
    

Running this reveals that there is one solution, Nigel owns the fish.

