Teaser 1915: Rabbit, rabbit, rabbit, …
From The Sunday Times, 30th May 1999 [link]
In each of the four houses in a small terrace lives a family with a boy, a girl and a pet rabbit. One of the children has just mastered alphabetical order and has listed them thus:
I happen to know that this listing gave exactly one girl, one boy and one rabbit at her, his or its correct address. I also have the following correct information: neither Harry nor Brian lives at number 3, and neither Donna nor Jumper lives at number 1. Gail’s house number is one less than Mopsy’s house number, and Brian’s house number is one less than Cottontail’s.
Who lives where?
This puzzle is included in the book Brainteasers (2002). The puzzle text above is taken from the book.
[teaser1915]

Jim Randell 9:58 am on 13 October 2020 Permalink |
See also: Teaser 2944.
This Python program runs in 44ms.
Run: [ @repl.it ]
from enigma import subsets, printf # the names girls = "ADGK" boys = "BEHL" rabbits = "CFJM" # choose an ordering where exactly k of the original ordering is correct def choose(xs, k=1): for ys in subsets(xs, size=len, select="P"): if sum(x == y for (x, y) in zip(xs, ys)) == k: yield ys # choose an ordering for the boys for boy in choose(boys): # "neither H nor B live at number 3 [= index 2]" if boy[2] == 'H' or boy[2] == 'B': continue # choose an ordering for the rabbits for rabbit in choose(rabbits): # "J does not live at number 1 [=index 0]" if rabbit[0] == 'J': continue # "B's number is one less than C's" if boy.index('B') + 1 != rabbit.index('C'): continue # choose an ordering for the girls for girl in choose(girls): # "D does not live at number 1 [= index 0]" if girl[0] == 'D': continue # "G's number is one less than M's" if girl.index('G') + 1 != rabbit.index('M'): continue # output solution for (n, (g, b, r)) in enumerate(zip(girl, boy, rabbit), start=1): printf("{n}: {g} {b} {r}") printf()Solution: The occupants of each house are:
LikeLike
Frits 4:56 pm on 13 October 2020 Permalink |
from enigma import SubstitutedExpression girls = ("", "Alice", "Donna", "Gail", "Kelly") boys = ("", "Brian", "Eric", "Harry", "Laurie") rabbits = ("", "Cottontail", "Flopsy", "Jumper", "Mopsy") # the alphametic puzzle p = SubstitutedExpression( [ # "B's number is one less than C's" "B + 1 = C", # "G's number is one less than M's" "G + 1 = M", # listing gave exactly one girl, one boy and one rabbit at # her, his or its correct address "sum((A == 1, D == 2, G == 3, K == 4)) == 1", "sum((B == 1, E == 2, H == 3, L == 4)) == 1", "sum((C == 1, F == 2, J == 3, M == 4)) == 1", ], answer="ADGK, BEHL, CFJM", digits=range(1,5), distinct=('ADGK', 'BEHL', 'CFJM'), # "D does not live at number 1" # "J does not live at number 1" # "neither H nor B live at number 3" d2i={1 : "CMDJ", 3 : "BH", 4 : "BG"}, verbose=0, #reorder=0, ) # Print answers for (_, ans) in p.solve(): for k in "1234": x = [j+1 for x in ans for j, y in enumerate(str(x)) if y == k] print(f"house {k}: {girls[x[0]]:<6} {boys[x[1]]:<7} {rabbits[x[2]]}") # house 1: Kelly Harry Flopsy # house 2: Alice Brian Jumper # house 3: Gail Eric Cottontail # house 4: Donna Laurie MopsyLikeLike
John Crabtree 6:34 pm on 13 October 2020 Permalink |
Flopsy must be at #1.
Brian cannot be at #2, otherwise Jumper and Mopsy are both correct or both incorrect.
And so Brian is at #1, Cottontail at #3, Jumper at #1, Mopsy at #4, and Gail at #3, etc
LikeLike