Sunday Times Teaser 3145 – Easier To Ask The Audience
by Danny Roth
Published Sunday January 01 2023 (link)
“I have forgotten the phone number!” complained Martha, about to phone a friend. “So have I!” replied George, “but I have some vague memories of it. It is a perfect square with all the digits different, and the last digit is equal to the number of digits to be dialled. The last-but-one digit is odd and one of the digits is zero. Also the second and third and last-but-one digits are all exact multiples of the first digit. Maybe you can work it out.”
Martha proceeded to dial the number correctly.
What number did she dial?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223from math import isqrt# the set of unit digits of squares with odd penultimate digitsunits = set(i ** 2 % 10 for i in range(10) if (i ** 2 // 10) & 1)# consider the possible lengths of the phone numberfor sq_len in units:# digits at positions 0, 1, 2, -2, -1 all non zero and different# plus one zero digit gives a minimum of six digitsfor r in range(317, isqrt(10 ** sq_len - 1) + 1):nbr = r ** 2# its penultimat digit is oddif (nbr // 10) & 1:# the digits of the numberd = [int(d) for d in str(nbr)]# its digits are all different with one zero ddigitif len(set(d)) == sq_len and d.count(0) == 1:# its second, third and last but two digits are exact# proper multiples of its first digitif all(n > d[0] and n % d[0] == 0 for n in (d[1], d[2], d[-2])):print(f"She dialled {nbr}.")