Sunday Times Teaser 2715 – Colour Coded
by Angela Newing
Five cyclists each have less than 12 helmets, none having two of the same colour and no two cyclists having the same number of helmets. Each wear their helmets in a fixed sequence of different colours on different days until all colours have been used once at which point they repeat their sequence.
On both 1st September and 1st October Alan, Bill, Charles, Dave and Eric wore mauve, red, red, orange and green respectively. On Septemeber 11th there was one mauve, one white, one green and two reds; on the 19th Dave wore orange, Eric wore green and the others wore red; on the 22nd and 23rd Eric wore orange and white respectively.
In the alphabetical order of their names what colour helmets did they wear on 11th of September?
-
brian gladman permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import permutationscolours = { 'm': 'Mauve', 'r': 'Red', 'o': 'Orange','g': 'Green', 'w': 'White' }# the order of helmet colours on the 1st of Septemberbase = 'mrrog'# the colours to be permuted for the 11th September orderunknown = 'mwgrr'# the colours on given days after 1st September (if known)d = {18:'rrrog', 21:'????o', 22:'????w'}# the possible numbers of helmets for the cyclistsnos = list(x for x in range(1, 12) if 30 % x == 0)# for storing solutions foundsol = set()# try all possible orders for the colours on the 11thfor p in permutations('mwgrr'):# add this order to our map of orders on given datesd[10] = ''.join(p)# permute the number of helmets owned the cyclistsfor nh in permutations(nos, 5):cnt = 0# now consider all cyclists and, for known colours on days# that are at the start of their helmet rotation sequences,# check that the colours match those at the startif all(all(d[n][i] == '?' or n % nh[i] or d[n][i] == base[i]for n in d) for i in range(5)):# now consider all cyclists again and, for known colours on days# that are NOT at the start of their helmet rotation sequences,# check that the colours do NOT match those at the startif all(all(d[n][i] == '?' or n % nh[i] == 0 or d[n][i] != base[i]for n in d) for i in range(5)):# store this solutionsol.add(p)for s in sol:print(' and '.join(colours[p] for p in s).replace(' and ', ', ', 3))