From The Sunday Times, 22nd September 1974 [link]
Ashley, Bill, Charles, David, and Edward are (not necessarily in that order), a dustman, a grocer, a miner, a blacksmith, and an artist, and all live on the right hand side of Strife Lane, in even numbered houses. All five are of different ages and no man has reached the age of retirement (65). All of course are upright and honest citizens, and never tell lies. However, I had forgotten what job each man did, where he lived, and how old he was, and so, to help me, each man volunteered the following statements:
Ashley:
(1) The artist lives at No. 10, next to Charles;
(2) Nobody lives next to the grocer, although Bill is only two doors away.
Bill:
(3) I am the only man whose age is indivisible by 9;
(4) I am 4 years older than Ashley;
Charles:
(5) The blacksmith’s age is 5 times his house number;
David:
(6) The miner lives 4 houses higher up the road from me;
(7) The miner’s age is 3 times the dustman’s house number, but he is two-thirds the dustman’s age;
Edward:
(8) The dustman is twice as old as David;
(9) I am the oldest man in the street.
At what number does Ashley live?
How old is the grocer?
Who is the artist?
This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.
[teaser688]
Jim Randell 8:44 am on 23 February 2021 Permalink |
As stated there are multiple solutions to the puzzle.
Having tackled similar problems before it seems likely that the intention of the setter is:
or possibly:
Any solution for the latter will appear as a solution for the former, so we will use the first one to solve the puzzle (as it turns out it does give a unique answer).
The following Python code generates possible sums that use a square and 2 other numbers to produce the required total, and where each of 9 digits is used exactly once in the summands.
It then choose sums that use different squares, but have one of the other numbers in common.
It runs in 95ms.
Run: [ @repl.it ]
from enigma import ( cproduct, powers, inf, is_duplicate, irange, concat, multiset, group, unpack, subsets, intersect, join, arg, printf ) # target sum Y = arg(2015, 0, int) printf("[Y={Y}]") # generate (s, a, b) sums, s is square, s + a + b = Y def generate(Y): # consider squares for s in powers(0, inf, 2): if s > Y: break if is_duplicate(s): continue # find sums: s + a + b = Y t = Y - s for a in irange(0, t // 2): b = t - a # check for sums with 9 different digits ds = concat(s, a, b) # check for 9 different digits if len(ds) == 9 and len(set(ds)) == 9: yield (s, a, b) # group sums by the square d = group(generate(Y), by=unpack(lambda s, a, b: s)) # collect the squares involved r = multiset() # consider squares for Harry and Tom for (sH, sT) in subsets(sorted(d.keys()), size=2): # choose decompositions for (dH, dT) in cproduct([d[sH], d[sT]]): # that share a number if intersect([dH, dT]): printf("[H = {dH}; T = {dT}]", dH=join(dH, sep=" + "), dT=join(dT, sep=" + ")) r.add((sH, sT)) # output solutions for (k, v) in r.most_common(): printf("squares = {k} [{v} solutions]", k=join(k, sep=", "))Solution: Harry’s square was 324. Tom’s square was 784.
There are two ways to arrive at the solution:
The summands in each sum use all the digits exactly once except for the digit 1.
To see the multiple solutions without the restriction that each of the 9 digits is used exactly once, you can remove line 15 and the [[
len(ds) == 9]] clause from line 24.The same puzzle could have been set in 2019, and had the same answer.
If the puzzle were set in 2022, there would only be one way to arrive at the (different) answer.
LikeLike
Frits 2:04 pm on 23 February 2021 Permalink |
I assumed Harry’s and Tom’s squares were not the number they shared (ABCD).
from enigma import SubstitutedExpression, is_square # the alphametic puzzle p = SubstitutedExpression( [ # Use 4-digit numbers as sum is limited to 2015 # to reduce the output assume EFGH (Harry) and MNOP (Tom) # are both perfect squares "is_square(EFGH)", # use a variable as right hand side to reduce the number of loops "2015 - ABCD - EFGH = IJKL", # nine different digits "len(str(ABCD) + str(EFGH) + str(IJKL)) == \ len(set(str(ABCD) + str(EFGH) + str(IJKL))) == 9", # Tom's included a higher perfect square "MNOP > EFGH and is_square(MNOP)", # use a variable as right hand side to reduce the number of loops "2015 - ABCD - MNOP = QRST", # nine different digits "len(str(ABCD) + str(MNOP) + str(QRST)) == \ len(set(str(ABCD) + str(MNOP) + str(QRST))) == 9", ], answer="EFGH, MNOP", d2i=dict([(k, "AEIMQ") for k in range(3, 10)]), verbose=0, distinct="", ) # Print answers sols = set(sol for (_, sol) in p.solve()) print(f"answer = {sols}")LikeLike