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 8:58 am on 5 December 2021 Permalink |
This is a “monkey and coconuts” problem (see: Enigma 258, Puzzle #86).
This program finds the first few possible solutions. The first of these is the only one that gives a viable price for the cottage (according to the published solution).
Run: [ @replit ]
from enigma import (irange, inf, div, arg, printf) def solve(): # consider selling price of the cottage for x in irange(5, inf, step=5): t = x # A's amount t -= 1 A = div(t, 4) if A is None: continue # B's amount t -= A + 1 B = div(t, 4) if B is None: continue # C's amount t -= B + 1 C = div(t, 4) if C is None: continue # D's amount t -= C + 1 D = div(t, 4) if D is None: continue # and each gets 1/4 of what is left t -= D + 1 q = div(t, 4) if q is None: continue yield (x, A + q, B + q, C + q, D + q) # find the first few solutions n = arg(1, 0, int, "number of solutions to find") for (i, (x, A, B, C, D)) in enumerate(solve(), start=1): printf("[{i}] x={x}; A={A} B={B} C={C} D={D}") if i == n: breakSolution: The value of the cottage was £2045.
The father keeps £5 and the split of the remaining £2040 is: A=672, B=544, C=448, D=376.
LikeLike
Jim Randell 9:37 am on 5 December 2021 Permalink |
Using this analysis [@wolfram] we see that the solutions to the problem are given by:
for k = 1, 2, 3, … where N is a multiple of 5.
And we can write a more efficient program:
from enigma import (irange, inf, ediv, arg, printf) def solve(): for k in irange(1, inf): x = 1024 * k - 3 if x % 5 != 0: continue # calculate amounts t = x - 1 A = ediv(t, 4) t -= A + 1 B = ediv(t, 4) t -= B + 1 C = ediv(t, 4) t -= C + 1 D = ediv(t, 4) t -= D + 1 q = ediv(t, 4) yield (x, A + q, B + q, C + q, D + q) # find the first few solutions n = arg(1, 0, int, "number of solutions to find") for (i, (x, A, B, C, D)) in enumerate(solve(), start=1): printf("[{i}] x={x}; A={A} B={B} C={C} D={D}") if i == n: breakLikeLike