Sunday Times Teaser 2488 – No Title
by Danny Roth
Published May 30 2010 (link)
Each of George’s and Martha’s five great-grandchildren celebrates a single-digit birthday today. “If you add their ages and reverse the digits of the total,” Martha said, “you get a two-figure number divisible by Andrew’s age and by none of the others’.” “That pattern continues,” George added. “Eliminate Andrew and the same is true of the other four, giving a number divisible by Brian’s age and none of the other three. If you eliminate Brian, the same is true for the other three with Colin’s age. Eliminating Colin, this works for the other two with David’s age.”
How old are the five children?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526from itertools import combinations# the reversed sum of the ages is divisible by only one age# (applied recursively)def test(ages):if not ages:return Trueelse:# form the digit sum and reverse its digitsa, b = divmod(sum(ages), 10)rev = 10 * b + a if a else b# it must be divisible by only one of the agesdiv = [a for a in ages if not rev % a]if len(div) == 1:# repeat the test with the remaining agesreturn test(ages.difference(div))else:return False# consider all combinations of five single digit agesfor ages in combinations(range(2, 10), 5):if test(set(ages)):*a, b = agesprint('Their ages are {}, {}, {}, {} and {}'.format(*a, b))