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 2:45 pm on 26 November 2021 Permalink |
A bit of a convoluted scenario, but the calculations are fairly straightforward.
The average number of sides must be an integer to construct the polygon, and so the average of the squares must also be an integer, and so must the internal angle. So we can keep everything in the integers.
This Python program runs in 46ms.
Run: [ @replit ]
from enigma import Primes, dsum, subsets, div, sq, is_square, printf primes = Primes(100) # candidate primes ps = list(p for p in primes.irange(10, 99) if dsum(p) in primes) # choose 4 of them for ns in subsets(ps, size=4): # calculate the mean, and mean square m = div(sum(ns), 4) m2 = div(sum(sq(n) for n in ns), 4) if m is None or m2 is None: continue # standard deviation sd = is_square(m2 - sq(m)) if sd is None: continue # internal angle a = div(360, m) if a is None or a % 2 == 0: continue # output solution printf("{ns}; m={m} m2={m2} sd={sd} a={a}", a=180 - a)Solution: The “standard deviation” is 15.
The prime numbers are: 23, 29, 47, 61.
Which give a mean of 40, and a mean square of 1825. And a regular 40-sided polygon has internal angles of 171°.
Without the regular polygon condition there are three potential integer solutions:
A 42-gon and 50-gon don’t have whole number internal angles, so the requirement for the angle to be odd isn’t necessary (although it may help in a manual solution).
LikeLike
Frits 5:44 pm on 26 November 2021 Permalink |
Starting from the (odd, even) divisor pairs of number 360.
from enigma import divisor_pairs, dsum, is_square P = {3, 5, 7} P |= {2} | {x for x in range(11, 100, 2) if all(x % p for p in P)} # candidate primes P = sorted(p for p in P if p > 9 and dsum(p) in P) # get_standard_deviation by decomposing number <t> into <k> increasing # numbers from <ns> so that sum(<k> numbers) equals <t> def get_standard_deviation(t, k, ns, sq_avg, s=[]): if k == 1: if t in ns and t > s[-1]: # average of the squares minus the square of the average is square sd = is_square(sum(x**2 for x in s + [t]) // 4 - sq_avg) if sd is not None: yield sd else: for n in ns: if s and n <= s[-1]: continue yield from get_standard_deviation(t - n, k - 1, ns, sq_avg, s + [n]) min_avg = sum(P[:4]) / 4 max_avg = sum(P[-4:]) / 4 penmax_avg = sum([P[-5]] + P[-3:]) / 4 # penultimate maximum # determine number of sides for all possible angles lst_nsides = [nsides for a, nsides in divisor_pairs(360) if a % 2 and min_avg <= nsides <= max_avg] # skip smallest angle if number of sides is too close to max_avg if penmax_avg < lst_nsides[0] < max_avg: lst_nsides = lst_nsides[1:] # solve for all possible angles for avg in lst_nsides: for sd in get_standard_deviation(4 * avg, 4, P, avg**2): print("answer:", sd)LikeLike