Brain-Teaser 891: Ups and downs
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:32 am on 23 December 2021 Permalink |
The electrician makes a journey by selecting buttons 9, 8, 7, …, 3, 2, 1, and in the process visits one of the floors twice and one of the floors no times. And the floor that is not visited is a lower number than the electrician’s floor (which is the only button that gives the correct floor).
I assumed there are exactly 3 buttons that go to floor exactly twice the number on the button, and exactly 2 that go to a floor exactly half the number on the button.
This Python 3 program chooses the buttons that go to floors twice and half their labelled values, and then fills out the rest of the mapping as it goes along. It runs in 53ms.
Run: [ @replit ]
from enigma import (irange, update, product, subsets, diff, singleton, trim, map2str, printf) # consider a journey made with buttons <bs>, visiting floors <fs> using map <m> (button -> floor) def journey(bs, fs, m): # are we done? if not bs: yield (fs, m) else: (b, f_) = (bs[0], fs[-1]) # is the button assigned? f = m.get(b, None) if f is None: (ss, upd) = (irange(0, 9), 1) else: (ss, upd) = ([f], 0) # choose a target floor for f in ss: # if unassigned: cannot be the right floor, or twice or half if upd and (f == b or f == 2 * b or b == 2 * f): continue # cannot be a previously visited floor, except for the final floor if (f in fs) != (len(bs) == 1): continue # journey cannot pass the correct floor if not (f_ < b < f or f_ > b > f): m_ = (update(m, [(b, f)]) if upd else m) yield from journey(bs[1:], fs + [f], m_) # exactly 3 buttons go to twice the number, exactly 2 buttons go to half the number for (ds, hs) in product(subsets([1, 2, 3, 4], size=3), subsets([2, 4, 6, 8], size=2)): # remaining floors rs = diff(irange(1, 9), ds + hs) if len(rs) != 4: continue # choose the floor for the electrician for e in rs: if e == 1: continue # initial map m0 = { 0: 0, e: e } m0.update((k, 2 * k) for k in ds) # doubles m0.update((k, k // 2) for k in hs) # halfs # consider possible journeys for the milkman for (fs, m) in journey([9, 8, 7, 6, 5, 4, 3, 2, 1], [0], m0): # the unvisited floor is lower than e u = singleton(x for x in irange(1, 9) if x not in fs) if u is None or not (u < e): continue # output solution printf("{fs} {m}", fs=trim(fs, head=1, tail=1), m=map2str(m, arr='->'))Solution: The milkman visited floors: 7, 4, 2, 3, 5, 8, 6, 9.
He then returns to floor 2, and finds he has already visited.
The rewired map of button → floor is:
LikeLike