From The Sunday Times, 24th April 1983 [link]
Fred and I usually do the washing and drying up in our commune. Fred always washes the largest saucepan first, then the second largest, and so on down to the smallest. In this way I can dry them and store them away in the order they were washed, by putting one saucepan inside the previously washed saucepan, ending up with a single pile.
Yesterday, the cook misread the quantities for the sherry trifle recipe, with the result that Fred got the washing up order completely wrong. For example, he washed the second smallest saucepan immediately after the second largest; and the smallest saucepan immediately before the middle-sized saucepan (i.e. the saucepan with as many saucepans larger than it as there are smaller).
I realised something was wrong when, having started to put the saucepans away in the usual manner, one of the saucepans did not fit the previously washed saucepan; so I started a second pile. Thereafter each saucepan either fitted in to one, but only one pile, or did not fit into any pile, in which case I started another pile.
We ended up with a number of piles, each containing more than one saucepan. The first pile to be completed contained more saucepans than the second, which contained more than the third etc.
In what order were the saucepans washed up? (Answers in the form a, b, c, …, numbering the saucepans from 1 upwards, 1 being the smallest).
This puzzle is included in the book The Sunday Times Book of Brainteasers (1994).
[teaser1081]
Jim Randell 9:52 am on 7 August 2024 Permalink |
See also: Enigma 1690.
The 16 numbers in the grid sum to tri(16) = 136, so each row and column must sum to 1/4 of this = 34.
We can use the [[
SubstitutedExpression]] solver from the enigma.py library to find possible assignments.The following run file executes in 85ms. (Internal runtime of the generated code is 145µs).
Solution: H + O + B + S + O + N = 73.
The completed grid is:
The Magic Square is a variation of the “Dürer” Magic Square seen in “Melencolia I”. [ @wikipedia ]
If you recognise that the given values (C = 3, E = 5, H = 8, I = 9, O = 15) fit into this square you don’t need to do any more working out, as the square is associative (which means any number and its symmetric opposite add to 17).
So we can calculate the required result using the given values as:
LikeLike
ruudvanderham 2:10 pm on 7 August 2024 Permalink |
Brute force solution:
import itertools C = 3 E = 5 H = 8 I = 9 O = 15 S = 19 for A, B, D, F, G, J, K, L, M, N, P in itertools.permutations((1, 2, 4, 6, 7, 10, 11, 12, 13, 14, 16)): ABCD = A + B + C + D if E + F + G + H == ABCD: if I + J + K + L == ABCD: if M + N + O + P == ABCD: if A + E + I + M == ABCD: if B + F + J + N == ABCD: if C + G + K + O == ABCD: if D + H + L + P == ABCD: if A + F + K + P == ABCD: if D + G + J + M == ABCD: print(f"{H+O+B+S+O+N=}") print(f"{A=:2} {B=:2} {C=:2} {D=:2}") print(f"{E=:2} {F=:2} {G=:2} {H=:2}") print(f"{I=:2} {J=:2} {K=:2} {L=:2}") print(f"{M=:2} {N=:2} {O=:2} {P=:2}")Output:
LikeLike
GeoffR 5:41 pm on 7 August 2024 Permalink |
A 4-stage permutation brings the run- time down to 55 msec using ABCD = 34 , or 177 msec not using ABCD = 34.
from enigma import Timer timer = Timer('ST2587', timer='E') timer.start() from itertools import permutations # A B C D # E F G H # I J K L # M N O P # Given values C, E, H = 3, 5, 8 I, O, S = 9, 15, 19 # Find remaining digits to permute digits = set(range(1,17)).difference({3, 5,8,9,15}) # 1st stage permutation for p1 in permutations (digits, 3): A, B, D = p1 # C given ABCD = A + B + C + D if ABCD != 34:continue # 2nd stage permutation q1 = digits.difference(p1) for p2 in permutations(q1, 2): F, G = p2 # E and H given EFGH = E + F + G + H if EFGH != ABCD:continue # 3rd stage permutation q2 = q1.difference(p2) for p3 in permutations(q2, 3): J, K, L = p3 # I given IJKL = I + J + K + L if IJKL != ABCD:continue # 4th stage permutation q3 = q2.difference(p3) for p4 in permutations(q3, 3): M, N, P = p4 # O given MNOP = M + N + O + P if MNOP != ABCD: continue # Check column and diagonal sums if A + E + I + M != ABCD:continue if B + F + J + N != ABCD:continue if C + G + K + O != ABCD:continue if D + H + L + P != ABCD:continue if A + F + K + P != ABCD:continue if D + G + J + M != ABCD:continue print(f"HOBSON = {H + O + B + S + O + N}") print(A,B,C,D) print(E,F,G,H) print(I,J,K,L) print(M,N,O,P) timer.stop() timer.report() # [ST2587] total time: 0.1775740s (177.57ms) - without ABCD = 34 # [ST2587] total time: 0.0553104s (55.31ms) - with ABCD = 34 # HOBSON = 73 # 16 2 3 13 # 5 11 10 8 # 9 7 6 12 # 4 14 15 1LikeLike
ruudvanderham 6:48 am on 8 August 2024 Permalink |
Nice solution.
I guess that if you first try the EFGH permutations, performance might slightly improve because there are only 2 choices there.
LikeLike
ruudvanderham 6:54 am on 8 August 2024 Permalink |
Or even faster (maybe): go vertical vertical and first do AEIM, then CGKO (twice 2 choices only).
LikeLike
Frits 10:00 am on 8 August 2024 Permalink |
Brian did some analysis and discovered that L must be 12.
[ https://brg.me.uk/?page_id=3378 ]
LikeLike
Jim Randell 11:03 am on 8 August 2024 Permalink |
@Frits: By using the given values and simplifying the 10 equations we can get:
And we know values for all the other letters in HOBSON, so the result follows directly.
(Although it is not a constructive solution – it assumes that it is possible to make a viable Magic Square).
LikeLike
Frits 11:56 am on 8 August 2024 Permalink |
That’s neat.
LikeLike
GeoffR 10:07 am on 8 August 2024 Permalink |
I got about a 5 ms speed increase trying the EFGH permutation first, but the second suggestion i.e. AEIM, then CGKO did not come out easily – may have another look later.
LikeLike
GeoffR 11:57 am on 9 August 2024 Permalink |
This solution uses the fact that this an associative magic square to find the value of HOBSON only. The full ten constraints for summing rows, columns and diagonals were still needed to find a unique magic square.
LikeLike