Teaser 2715: Colour coded
From The Sunday Times, 5th October 2014 [link] [link]
Five lads cycle together daily. Each has a different number of helmets, less than a dozen, and none of them has two of the same colour. Each wears in daily rotation all the cycle helmets he possesses. On 1st September, Alan wore mauve, Bill and Charles wore red, Dave orange and Eric green. On 11th September, two were red, one green, one mauve and one white. On 19th September, Dave’s was orange, Eric’s green and the others red. Eric wore orange on the 22nd and white on the 23rd. On 1st October all five wore the same as on 1st September.
In alphabetical order of the riders, what were the helmet colours on the 11th September?
[teaser2715]
Jim Randell 9:18 am on 28 February 2023 Permalink |
I am assuming that each cyclist cycles(!) through their helmets in strict rotation. So each time through they wear the same colours in the same order.
None of them have duplicate colours, so if we see one of them wearing the same colour on different days, they must have completed a whole number of cycles between those days. And they are all wearing the same colours on 1st September and 1st October, so the length of each of their cycles must be a divisor of 30, less than 12 (i.e. 1, 2, 3, 5, 6, 10).
For any given cyclist, if we are given a set of days and colours then we can look at days when the same colour is worn. The gap between the days must be a multiple (possibly 1) of the cycle length. And so by considering all possible gaps we can can determine possible cycle lengths. Furthermore, different colours must be worn on different days in the cycle. So
This Python program calculates possible cycle lengths from the colours given on the specified dates.
It runs in 55ms. (Internal runtime is 2.2ms).
Run: [ @replit ]
from enigma import ( subsets, group, unpack, union, tuples, mgcd, divisors, seq_all_different, delete, update, rev, map2str, printf ) # find cycle lengths for values give in ms def solve(ms, ns=dict()): # are we done? if not ms: yield ns else: # choose a key to process (the one with the most entries) x = max(ms.keys(), key=(lambda k: len(ms[k].keys()))) # group days by colour g = group(ms[x].items(), by=unpack(lambda k, v: v), f=unpack(lambda k, v: k)) # collect multiples of cycle length s = union((abs(b - a) for (a, b) in tuples(vs, 2)) for vs in g.values()) # consider possible cycle lengths (must be < 12) for n in divisors(mgcd(*s)): if n > 11: break # is this one already used? if n in ns: continue # check different colours give different cycle days if not seq_all_different(vs[0] % n for vs in g.values()): continue # solve for the remaining items yield from solve(delete(ms, [x]), update(ns, [(n, x)])) # consider possible orderings for 11th for (a, b, c, d, e) in subsets('RRGMW', size=len, select='mP'): # known positions (day 1 = 1st September) ms = dict( A={ 1: 'M', 11: a, 19: 'R', 31: 'M' }, B={ 1: 'R', 11: b, 19: 'R', 31: 'R' }, C={ 1: 'R', 11: c, 19: 'R', 31: 'R' }, D={ 1: 'O', 11: d, 19: 'O', 31: 'O' }, E={ 1: 'G', 11: e, 19: 'G', 22: 'O', 23: 'W', 31: 'G' }, ) # find possible cycle lengths for ns in solve(ms): # output solution printf("day 11: (A B C D E) = ({a} {b} {c} {d} {e}) {ns}", ns=map2str(rev(ns), sep=" ", enc="[]"))Solution: On 11th September, the colours were: Alan = mauve; Bill = red; Charles = red; Dave = green; Eric = white.
Alan has 5 or 10 helmets. Bill has 1 or 2. Charles has 2 or 1. Dave has 3. Eric has 6.
We can’t work out all the colours, but here is what we do know:
However these cycle lengths are chosen, they all give the same sequence of values for the 11th September.
LikeLike