Teaser 2629: Random road
From The Sunday Times, 10th February 2013 [link] [link]
George and Martha moved into Random Road, which has 99 houses along just one side. But instead of being numbered 1 to 99 in the usual way, the man given the job of numbering them gave the first house a number equal to his age and then kept adding his age again for each subsequent house, ignoring the hundreds digits and above. (So, had he been 37 then the numbers would have been 37, 74, 11, 48, 85, 22, etc). Luckily each house got a different number. George’s house number was “correct” so he did not immediately notice. He only saw that something was amiss when Martha pointed out that a house next door had a number with the same two digits as theirs, but in reverse order.
What is George’s and Martha’s house number? And how old was the numberer?
[teaser2629]
Jim Randell 9:01 am on 11 July 2023 Permalink |
The house numbers in positions k = 1 .. 99 are defined as:
or:
So numberers with the same age mod 100 will give the same sequence. We can suppose that the numberers age lies in the range 16 – 115, so we can identify the ages by the residue mod 100.
We are looking for a 2-digit house number XY that appears in the “correct” position, i.e.:
And has a neighbouring house whose number is YX:
I am assuming that 1-digit numbers are represented with a single digit.
This Python program runs in 54ms. (Internal runtime is 1.4ms).
Run: [ @replit ]
from enigma import (irange, nreverse, printf) # find solutions for age <n> def solve(n): # map: position -> house number (d, seen) = (dict(), set()) (p, k) = (1, n) while p < 100: if k == 0 or k in seen: break d[p] = k seen.add(k) k = (k + n) % 100 p += 1 # did we allocate all the houses? if p == 100: # look for a house with a 2-digit number the same as position for (p, k) in d.items(): if not (k > 9 and k == p): continue # look for neighbouring houses with the reverse of the number r = nreverse(k) if not (r > 9): continue if d.get(p - 1, 0) == r: yield (n, (p, k), (p - 1, r)) if d.get(p + 1, 0) == r: yield (n, (p, k), (p + 1, r)) # consider possible ages (mod 100) for n in irange(0, 99): for (n, (p0, k0), (p1, k1)) in solve(n): printf("age = {n} -> pos {p0} = {k0}, pos {p1} = {k1}")Solution: George and Martha’s house number is 25. The numberer’s age was 73.
We have:
The complete mapping is:
So 25 is in the correct position, and 24 has the number that is the reverse of 25.
50 and 75 are also in the correct position, but are not neighbours of 5 or 57 (respectively).
62 is given the number 26, the reverse of its position.
LikeLike
Jim Randell 10:22 am on 11 July 2023 Permalink |
Without checking that each house is assigned a different number there is only one candidate solution (but we can provide an additional check to ensure the answer is viable).
This run file executes in 62ms. (Internal runtime of the generated program is 1.3ms).
Run: [ @replit ]
#! python3 -m enigma -rr # AB = age of the numberer # XY = George and Martha's house number SubstitutedExpression --distinct="XY" --code="num = lambda n, k: (n * k) % 100" # G&M's house number is the same as its position "num(AB, XY) == XY" # a neighbouring house is numbered YX "YX in { num(AB, XY - 1), num(AB, XY + 1) }" # answer is: G&M's number, numberers age --answer="(XY, AB)" # check each house is assigned different number --reorder=0 "seq_all_different(num(AB, k) for k in irange(1, 99))"LikeLike