From The Sunday Times, 3rd September 1978 [link]
An electrician living in a block of flats has played a joke on the tenants by rewiring the lift. The buttons numbered 0 to 9 in the lift should correspond to the ground floor, first floor, etc., but he has rewired them so that although (for his own convenience) the buttons for the ground floor and his own floor work correctly, no other button takes you to its correct floor. Indeed when you get in the lift on the ground floor and go up, three of the buttons take you twice as high as they should, and two buttons take you only half as high as they should.
The milkman is unaware of the rewiring and so early yesterday morning, rather bleary-eyed, he followed his usual ritual which consists of taking nine pints of milk into the lift, pushing button 9, leaving one pint of milk when the lift stops, pushing button 8, leaving one pint of milk when the lift stops, and so on in decreasing order until, having pushed button and having left his last pint, he usually returns to his van.
However, yesterday when he tried to follow this procedure all seemed to go well until, having pushed button 1 , when the lift stopped he found a pint of milk already there. So he took the remaining pint back to his van, with the result that just one of the tenants (who lived on one of the floors below the electrician’s) did not get the pint of milk she’d expected.
The surprising thing was that during the milkman’s ups and downs yesterday he at no time travelled right past the floor which he thought at that time he was heading towards.
List the floors which received milk, in the order in which the milkman visited them.
This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.
[teaser891]
Jim Randell 7:20 pm on 21 January 2022 Permalink |
I am assuming notes that are an octave apart are considered identical. So going up three notes from M to P gives the same note as going down 4 notes from M to P. Also that chords are identical if they contain the same three notes, and a chord change requires at least one of the notes to change.
This Python program constructs the graph of transitions between chords, and then finds paths from JNP back to JNP that traverse all the edges (Eulerian circuits). We then apply the remaining conditions, and find the 7th element of the paths.
It runs in 51ms.
Run: [ @replit ]
from enigma import (mod, all_different, ordered, tuples, Accumulator, join, printf) # there are 7 notes in the scale fn = mod(7) # format a sequence, 0..6 represent J..P fmt = lambda s: join("JKLMNOP"[i] for i in s) fmts = lambda ss: join((fmt(s) for s in ss), sep=" ", enc="()") # start node = JNP start = (0, 4, 6) assert fmt(start) == 'JNP' # generate changes for chord <s> def changes(s): (x1, y1, z1) = (fn(n + 1) for n in s) (x2, y2, z2) = (fn(n - 2) for n in s) for t in ((x2, y1, z1), (x1, y2, z1), (x1, y1, z2)): t = ordered(*t) if t != s and all_different(*t): yield t # generate possible transitions, starting with <start> adj = dict() trans = set() ns = {start} while ns: ns_ = set() for s in ns: ts = set(changes(s)) adj[s] = ts trans.update((s, t) for t in ts) ns_.update(ts) ns = ns_.difference(adj.keys()) # find sequences that use every transition in <ts>, starting from <ss> def seqs(ts, ss): # are we done? if not ts: yield ss else: # make a transition s = ss[-1] for x in adj[s]: t = (s, x) if t in ts: yield from seqs(ts.difference([t]), ss + [x]) # find viable sequences def generate(trans, start): for ss in seqs(trans, [start]): # sequence must be a circuit if ss[0] != ss[-1]: continue # find the indices of start js = list(j for (j, x) in enumerate(ss) if x == start) # and distances between them ds = list(j - i for (i, j) in tuples(js, 2)) # first distance is greater than last if not (ds[0] > ds[-1]): continue # return (distances, sequence) yield (ds, ss) # find the smallest first distance r = Accumulator(fn=min, collect=1) for (ds, ss) in generate(trans, start): r.accumulate_data(ds[0], ss) # output solutions for ss in r.data: printf("{x} {ss}", x=fmt(ss[6]), ss=fmts(ss))Solution: The seventh chord in the sequence is: KNO.
The complete sequence is:
[Follow the [@replit] link, click on “Show Files”, and select “Teaser 3096.mp3” to hear the chords played with J–P transposed to notes A–G in a single octave].
There are 4 chords between the first two JNPs, and 3 chords between the last two JNPs.
And this is the only progression of the form (JNP [4] JNP [3] JNP).
There are 4 other viable progressions of the form (JNP [5] JNP [2] JNP), but we are only interested in progressions with the shortest possible distance between the first two occurrences of JNP.
LikeLike