Sunday Times Teaser 2923 – Powerful Numbers
by Danny Roth
Published September 30 2018 (link)
George and Martha’s five daughters have been investigating large powers of numbers. Each daughter told the parents that they had worked out a number which was equal to its last digit raised to an exact power. When Andrea announced her power, the parents had a 50% chance of guessing the last digit. When Bertha announced a larger power, the same applied. When Caroline announced her power, the parents had only a 25% chance of guessing the last digit; with Dorothy’s larger power, the same applied. When Elizabeth announced hers, the parents only had a 12.5% chance of guessing the last digit. I can tell you that the five powers were consecutive two-digit numbers adding up to a perfect square.
What, in alphabetical order of the daughters, were the five powers?
-
Brian Gladman permalink12345678910111213141516171819202122232425262728from itertools import productfrom collections import defaultdictnames = ('Andre', 'Bertha', 'Caroline', 'Dorothy', 'Elizabeth')# return true if an integer (x) is a squareis_sqr = lambda x: int(x ** 0.5) ** 2 == x# consider the middle integer of sequences of five consecutive# two-digit integers with sums that are perfect squaresfor b in (n for n in range(12, 98) if is_sqr(5 * n)):# map exponents to units digits (2..9) that produce# powers with the same unit digitspower_to_digits = defaultdict(list)for pwr, unit_digit in product(range(b - 2, b + 3), range(2, 10)):if pow(unit_digit, pwr, 10) == unit_digit:power_to_digits[pwr].append(unit_digit)# sort the powers on the number of units digits that produce compliant numberspwr_dgts_pairs = sorted(power_to_digits.items(), key=lambda x:len(x[1]))# to obtain 50%, 50%, 25%, 25% and 12.5% probability of guessing the unit# digits, the powers must have 2, 2, 4, 4 and 8 possible digitsif [len(dgts) for pwr, dgts in pwr_dgts_pairs] == [2, 2, 4, 4, 8]:# print the powers for the daughters in alphabetical orderprint(f"{', '.join(f'{n} {p}' for (p, d), n in zip(pwr_dgts_pairs, names))}.")