Brain-Teaser 884: Mice in the works
From The Sunday Times, 16th July 1978 [link]
Recently a hot-drink vending machine was installed in our office. Very nice it is too — completely up to date it was when it was bought. There are five switches, a slot for your money, and a button. The switches are labelled TEA, COFFEE, CHOCOLATE, MILK and SUGAR, and you select the combination you want, put in your money, press the button, and out comes your drink. Why, you can even have coffolatea if you want!
At least, this is the idea. Unfortunately, during the ten years it has been in store, “awaiting approval”, mice have chewed up the wiring. Mice with soldering irons, I should think. The result is now that no switch affects its “own” ingredient at all, but instead turns on two other ingredients, each ingredient being turned on by two different switches. However, if two switches are set which turn on the same ingredient, then they cancel each other out, and that ingredient doesn’t come out at all.
The result is somewhat chaotic, though occasionally some of the output is actually drinkable. For instance, when you ask for white sweet coffee, you get unsweetened milky tea; when you ask for sweet milky chocolate, you get sweet chocolate without milk; and when you ask for unsweetened milky tea you get a glorious gooey mocha — i.e. chocolate and coffee with milk and sugar.
Luckily, pressing the “deliver” button reinstates the original chaos, so that setting the same switches always gives the same results.
So, what is the easiest way to get white coffee without sugar? (i.e. Name the fewest switches that will deliver just coffee and milk).
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.
[teaser884]
Jim Randell 9:12 am on 18 November 2021 Permalink |
We’ve seen puzzles like this before. See Enigma 91, Puzzle #103 (although this puzzle was published before either of them).
I reused the code I wrote for Puzzle #103.
The following Python 3 program runs in 60ms.
Run: [ @replit ]
from enigma import (multiset, subsets, diff, update, ordered, join, map2str, printf) # buttons buttons = 'T Cf Ch M S'.split() # map each value in <ks> to <n> other values chosen from mutliset <vs> # return map d: <ks> -> <n>-tuples from <vs> def make_map(ks, vs, n=2, d=dict()): # are we done? if not ks: yield d else: # choose n values for the next key k = ks[0] for ss in subsets(diff(vs.keys(), [k]), size=n): yield from make_map(ks[1:], vs.difference(ss), n, update(d, [(k, ordered(*ss))])) # outcome of selecting buttons <bs> using map <d> def select(d, bs): m = multiset() for b in bs: m.update_from_seq(d[b]) return set(k for (k, v) in m.items() if v == 1) # consider possible maps for d in make_map(buttons, multiset.from_seq(buttons, count=2)): # select M+S+Cf -> M+T if not (select(d, ['M', 'S', 'Cf']) == {'M', 'T'}): continue # select S+M+Ch -> S+Ch if not (select(d, ['S', 'M', 'Ch']) == {'S', 'Ch'}): continue # select M+T -> Ch+Cf+M+S if not (select(d, ['M', 'T']) == {'Ch', 'Cf', 'M', 'S'}): continue # answer, easiest way to get Cf+M? for bs in subsets(buttons, min_size=1): if select(d, bs) == {'Cf', 'M'}: fmt = lambda s: join(sorted(s), sep="+") printf("{bs} -> Cf+M {d}", bs=fmt(bs), d=map2str(((k, fmt(v)) for (k, v) in d.items()), arr="->", enc="[]"))Solution: The easiest way to get coffee and milk is to select “Coffee” and “Milk”.
There is also a combination of 3 buttons that will give coffee and milk: “Chocolate”, “Tea” and “Sugar”.
The items delivered by the buttons are:
LikeLike
John Crabtree 5:44 pm on 25 November 2021 Permalink |
Using the same switch twice selects nothing. Using all five switches selects nothing. Call this statement S4
Using all of the switches in statements S1, S2, S3 and S4 results in: using S gives Cf and T
S1 reduces to: using Cf and M gives Cf and M
This is one possible answer, but we do not know that it is the shortest.
From S1 and S, using M gives Cf
From S2 and S, using M gives Ch as well as Cf (from above)
From S1, using Cf gives Ch and M
From S2, using Ch gives S and T
From S3, using T gives M and S
Since no one button gives Coffee with Milk, pressing Coffee and Milk is the simplest way to get Coffee with Milk
This solution is much simpler that the official one in the book.
LikeLike