Sunday Times Teaser 2832 – A New Year Reminiscence
by Victor Bryant
Published: 1 January 2017 (link)
Whilst filing away last year’s diary this morning I came across an old diary from my teenage years. In it I can see that in one particular month I went to four parties, three of them being on Saturdays and the other on a Sunday. I wrote down the four dates of the parties in words (in the format “January first” etc) and found that each of the dates used a different prime number of letters.
What were the four dates that I wrote down?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738394041424344454647from collections import defaultdictfrom itertools import combinations, productmonths = ( 'January', 'February', 'March', 'April', 'May','June', 'July', 'August', 'September', 'October','November', 'December' )days = ( 'first', 'second', 'third', 'fourth', 'fifth', 'sixth','seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth','thirteenth', 'fouteenth', 'fifteenth', 'sixteenth','seventeenth', 'eighteenth','nineteenth', 'twentieth','twentyfirst', 'twentysecond', 'twentythird','twentyfourth','twentyfifth', 'twentysixth', 'twentyseventh', 'twentyeighth','twentyninth', 'thirtieth', 'thirtyfirst' )# days in monthdim = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )primes = { 2, 3, 5, 7, 11, 13, 17, 19 }# map the months to the number of letters in (month, day) dates# that are prime and then to the days in the month with dates# that have this number of lettersm2l2d = defaultdict(lambda:defaultdict(list))for i, m in enumerate(months):for j, d in enumerate(days[:dim[i]]):l = len(m + d)if l in primes:m2l2d[m][l].append(j + 1)# consider each monthfor m in m2l2d.keys():# consider all combinations of four different date lengthsfor l4 in combinations(m2l2d[m], 4):# and all combinations of days with these lengthsfor d4 in product(*(m2l2d[m][l] for l in l4)):# look for a set of four days with three on the same# weekday and one on the following weekdaywk = [d % 7 for d in d4]ct = {wk.count(x):x for x in wk}try:if (ct[1] - ct[3]) % 7 == 1:print('{} {}th, {}th, {}th and {}th.'.format(m, *d4))except KeyError:continue