New Scientist Enigma 508 – A Colourful Deception
by Keith Austin
From Issue #1660, 15th April 1989
Tour the Tulip Fields of Bulbania
The towns are Aldingsp , Beachhol, Chholbea, Dingspal, Eachholb, Fresh and Gspaldin. The colours (Blue Red, Yellow) are those of the tulips in that area. You will fly to Eachholb and then drive by coach, visiting each town exactly once.
“Miss Wheel, I understand you will be driving the coach for the tour. I am afraid we have a problem. The flight is being diverted to Chholbea, so you w ill collect your passengers there.
We do not want the tourists to realise there has been a change to the tour as advertised on the above leaflet, as they might ask for their money back. Now, they will not be able to read the names of the towns as they are in Bulbattian, but they can tell the colours of tulips and they have the map. I want you to start at Chholbea and drive round visiting each town exactly once, but so that as the tourists notice the colours on each side of the road, they will believe from their map that they are following a route as described on the leaflet, beginning at Eachholb.”
What route did Miss Wheel take and what route did the tourists think they were taking?
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546from collections import defaultdict# list the destinations of the roads from each townadj = {'A': 'BEFG', 'B': 'ACG', 'C': 'BDG', 'D': 'CEFG','E': 'ADF', 'F': 'ADEG', 'G': 'ABCDF'}# list the colours on the left and right of the road# between two towns when going from first to secondcol = {'AB': 'BR', 'AE': 'YR', 'AF': 'BY', 'AG': 'RB','BC': 'YB', 'BG': 'BR', 'CD': 'RY', 'CG': 'YB','DE': 'YB', 'DF': 'BR', 'DG': 'RY', 'EF': 'YB','FG': 'BR'}# find a route that visits each town oncedef find_route(r):if len(r) == 7:yield relse:for n in adj[r[-1]]:if n not in r:yield from find_route(r + n)# compile the colour sequences seen on the left# and the right when passing along a routedef col_seq(r):lc, rc = '', ''for f, t in zip(r, r[1:]):ll, rr = col[f + t] if f < t else col[t + f][::-1]lc += llrc += rrreturn lc, rc# map the colour sequences seen on routes from E# to the routes on which they occurcs2r = defaultdict(list)for r in find_route('E'):cs2r[col_seq(r)].append(r)# consider routes from C looking for any that produce# the same unique colour sequence on a route from Efor r in find_route('C'):cs = col_seq(r)if cs in cs2r and len(cs2r[cs]) == 1:print(f"Actual route {r} (planned route {cs2r[cs][0]}).")