Sunday Times Teaser 2754 – Family History
by Danny Roth
Published: 5 July 2015 (link)
Three of George’s relatives who were born in different years of the 20th century shared the same birthday. Writing these in the form D/M/Y with just two digits for the year, he tells Martha that: in one case D divided by M, when expressed as a percentage, is Y; in another M is the average of D and Y; in the remaining one D raised to the power M equals Y. George then told Martha that knowing the day, D, would not enable her to work out the three dates, but knowing any one of the three years would enable her to work out all three dates.
What is the most recent of the three birth dates?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738from collections import Counter, defaultdictfrom itertools import product# for counting possible birth yearsctr = Counter()# for collecting results for each dayd_to_my3 = defaultdict(list)# consider all day and month valuesfor day, mth in product(range(1, 32), range(1, 13)):# one birth year is the day divided by the month# as a percentagey1, r = divmod(100 * day, mth)if not r:# calculate the other two birth yearsyrs = y1, 2 * mth - day, day ** mth# all three must be two digit valuesif all(x < 100 for x in yrs):# count all the possible year valuesctr += Counter(yrs)# store lists of possible answers for each dayd_to_my3[day] += [(mth, yrs)]# consider possible solutions for each dayfor day, l_my3 in d_to_my3.items():# the day does not lead to a unique solutionif len(l_my3) > 1:for mth, y3 in l_my3:# any of the three years in a solution can identify# it - so each year must occur in only one solutionif all(ctr[y] == 1 for y in y3):# output the most recent birth datefs = 'The most recent birth date is 0{}/0{}/19{}.'print(fs.format(day, mth, max(y3)))