Sunday Times Teaser 2524
by Victor Bryant
Published: 6 February 2011 (link)
My birthday is on the first of a month. My three logical friends Lettice, Daisy and Bertha wanted to know which month. So I whispered to Lettice the number of letters in the spelling of the month, I whispered to Daisy the number of days in the month, and I whispered to Bertha the day of the week of my birthday this year. I explained to all three what I had done and then I asked them in turn whether they were able to work out the month yet. Their replies were:
Lettice, no; Daisy, no; Bertha, no.
Lettice, no; Daisy, no; Bertha, yes.
What is my birthday month?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233343536373839404142434445464748from calendar import month_name, monthrangefrom collections import defaultdictfrom operator import eq, gt# month name lengthsmonth_nln = list(len(x) for x in month_name)[1:]# month lengthsmonth_len = list(monthrange(2011, m)[1] for m in range(1, 13))# month weekday of first daymonth_1st = list(monthrange(2011, m)[0] for m in range(1, 13))# collect months into groups based on the criterion defined by the# function 'group_by' and return two lists, the first listing items# that are unique, the second listing those that are notdef filter(months, group_by):# group the itemsd = defaultdict(list)for m in months:d[group_by[m]] += [m]# collect them into unique and non unique listsunique, not_unique = [], []for k, g in d.items():(unique if len(g) == 1 else not_unique).extend(g)return unique, not_uniquemonths = list(range(12))# Lettice 'no': no month with a unique month name lengthmonths = filter(months, month_nln)[1]# Daisy 'no': no remaining month with a unique month lengthmonths = filter(months, month_len)[1]# Bertha 'no': no remaining month with a unique initial weekdaymonths = filter(months, month_1st)[1]# Lettice 'no': no remaining month with a unique month name lengthmonths = filter(months, month_nln)[1]# Daisy 'no': no remaining month with a unique month lengthmonths = filter(months, month_len)[1]# Bertha 'yes': there is a remaining month with a unique initial weekdaymonths = filter(months, month_1st)[0]print('The Birthday is in {}.'.format(month_name[months[0] + 1]))