Sunday Times Teaser 2746 – Five Finger Exercise
by Danny Roth
Published: 10 May 2015 (link)
George and Martha have a five-figure code for their burglar alarm. George commented that the three-figure number formed by the first three digits of the code equalled the sum of the cubes of those first three digits. Martha added that the three-figure number formed by the last three digits of the code equalled the sum of the factorials of those three digits. (She had to remind George what a factorial was — he remembered once she had pointed out that the factorial of 4 was 4x3x2x1 = 24.)
What is their code?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415from math import factorial as facfrom itertools import product# compose the three digit number from the last three digits of the codefor c, d, e in product(range(1, 10), range(10), range(10)):# and check it is equal to the sum of the factorials of its digitsif 100 * c + 10 * d + e == fac(c) + fac(d) + fac(e):# compose the three digit number from the first three digits of the codefor a, b in product(range(1, 10), range(10)):# and check it is equal to the sum of the cubes of its digitsif 100 * a + 10 * b + c == a ** 3 + b ** 3 + c ** 3:code = int(''.join(str(x) for x in (a, b, c, d, e)))print('Their code is:', code)