Sunday Times Teaser 2780 – Calendar Dice
by Victor Bryant
Published: 3 January 2016 (link)
I have tried to make a calendar using some dice. To display the month I want to use three dice, with a capital letter on each of the faces to display
JAN or FEB or MAR etc.
I chose the capital letters on the dice to enable me to go as far as possible through the year. Furthermore, it turned out that one particular die contained four vowels.
(a)What was the last month that I was able to display?
(b)What were the two other letters on that particular die?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334from itertools import permutationsfrom copy import deepcopymonths = ('January', 'February', 'March', 'April', 'May', 'June', 'July','August', 'September', 'October', 'November', 'December' )# try to add months composing possible dice as we godef add_month(dice, mnth):# if we have got further than the current highest monthif mnth >= max_mnth:yield mnth, dice# check the ways of placing the next month's three letters# on the three dicefor p in permutations(months[mnth][:3].upper()):# add the letters to the three diced2 = deepcopy(dice)for d, l in zip(range(3), p):d2[d].add(l)# assume a maximum of six sides on each diceif all(len(d) <= 6 for d in d2):# proceed to the next monthyield from add_month(d2, mnth + 1)# for the maximum month reached and the dice usedmax_mnth, dce = 0, Nonefor mnth, dice in add_month([set('J'), set('AEOU'), set('N')], 1):max_mnth, dce = mnth, dicefs = '(a) {} is the last month; (b) the consonants with the vowels are {}.'ltrs = ' and '.join(sorted(dce[1] - set('AEOU')))print(fs.format(months[max_mnth - 1], ltrs))