Sunday Times Teaser 2589 – A Certain Age
by Robin Nayler
Published: 6 May 2012 (link)
My cousin and I share a birthday. At the moment my age, in years, is the same as hers but with the order of the two digits reversed. On one of our past birthdays I was five times as old as her but, even if I live to a world record “ripe old age”, there is only one birthday in the future on which my age will be a multiple of hers.
How old am I?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223# consider my age in a reasoable rangefor my_age in range(10, 101):a, b = divmod(my_age, 10)cousins_age = 10 * b + a# the cousin is youngerif cousins_age <= my_age:# consider earlier years when both are alivefor past in range(1, cousins_age):q, r = divmod(my_age - past, cousins_age - past)# looking for my age being five times hers at the timeif r == 0 and q == 5:l = []# now go forward and store future for any dates where# my age is a multiple of hersfor future in range(1, 100):q, r = divmod(my_age + future, cousins_age + future)if r == 0 and q > 1:l += [(future, q)]# the solution exhibits only one multipleif len(l) == 1:print("My age is {}.".format(my_age))