Sunday Times Teaser 2510 – No Title
by Danny Roth
Published October 31 2010 (link)
Since we last met them, George has moved departments yet again and Martha has forgotten the extension number.
“No problem,” said the operator.
“If you write down the number itself, the average of its four digits, the sum of its four digits, and the cube root of the difference between the number and its reverse (which is smaller), then you will write no digit more than once.”
What is George’s new extension number?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849from itertools import product# If the number minus its reverse is n^3, we obtain## n^3 = 999.(a - d) + 90.(b - c)## Since the right hand side is divisible by 3, n must have a# 3 as a factor with n^3 hence being a multiple of 3^3; so:## (n / 3)^3 = {37.(a - c) + 10.(b - c) / 3}## where (b - c) is a multiple of 3 and (n / 3) < 8# map cubes (n) less than eight to the set of digits in# (3 * n), removing values that have duplicate digitscubes = {x:str(3 * x) for x in range(1, 8)}cubes = {x:set(int(x) for x in v)for x, v in cubes.items() if len(v) == len(set(v))}# consider all values for the two middle digitsfor b, c in product(range(10), repeat=2):if b == c or (b - c) % 3:continues1 = set(range(10)).difference((b, c))# consider possible values of (n / 3)for no3 in cubes:# find a - d from the equation above for (n / 3)^3amd, r = divmod(no3 ** 3 - 10 * (b - c) // 3, 37)if r or not cubes[no3] < s1:continues2 = s1.difference(cubes[no3])# consider possible values for the number's first digit (a)for a in s2:s3 = s2.difference([a])# find the last digit (d) from |a - d|for d in s3.intersection((a - amd, a + amd)):# form the sum and the average of the number's digitssm = a + b + c + dav, r = divmod(sm, 4)# integer average and the number is larger than its reverseif not r and a > d:s4 = s3.difference([d])dgts = tuple(int(x) for x in str(sm) + str(av))if len(dgts) == len(set(dgts)) and set(dgts) <= s4:nb = 1000 * a + 100 * b + 10 * c + dprint(f"George's extension is {nb}.")