Brainteaser 1153: Teasing square
From The Sunday Times, 7th October 1984 [link]
The diagram shows part of a magic square (a 3×3 array of positive whole numbers each of whose rows, columns and long diagonals adds up to the same total). But in this case only five of the numbers are shown. And each digit has been replaced by a letter, different letters representing different digits.
To add to the squareness of this magic I can tell you also that the sum of each row is a perfect square.
What is the full (numerical) version of the magic square?
[teaser1153]

Jim Randell 9:07 am on 5 August 2025 Permalink |
Here is a solution using the
SubstitutedExpressionsolver from the enigma.py library.It runs in 77ms. (Internal runtime of the generated code is 382µs).
Solution: The completed square is:
And so the magic constant is 81.
Which would correspond to: [X, XA, AB], [BR, AI, N], [TE, A, BY] for some unused symbols X and Y.
LikeLike
Frits 2:07 pm on 5 August 2025 Permalink |
Minimising the number of iterations.
# magic constant M = 3 * AI or AI = 3 * k^2 for AI in [3 * k * k for k in range(2, 6)]: A, I = divmod(AI, 10) # A can never be equal to I as AI is not a multiple of 11 M = 3 * AI sum2 = M - AI # BR + N = sum2 if sum2 > 105: continue # BR = A + 2.(c33 - AI) so R and A have the same parity # (sum2 - N) has same parity as A so N must have the same parity as A for N in set(range(A % 2, 10, 2)) - {A, I}: B, R = divmod(sum2 - N, 10) if not (0 < B < 10) or not {A, I, N}.isdisjoint({B, R}): continue c33 = ((BR := 10 * B + R) - A + sum2) // 2 T, E = divmod(M - c33 - A, 10) if not (0 < T < 10) or not {A, I, N, B, R}.isdisjoint({T, E}): continue c11 = sum2 - c33 c12 = sum2 - A c13 = sum2 - (TE := 10 * T + E) mat = [(c11, c12, c13), (BR, AI, N), (TE, A, c33)] # double check matrix if not all(sum(r) == M for r in mat): continue if len({sum2, c11 + c33, TE + c13}) > 1: continue if not all(sum(r) == M for r in zip(*mat)): continue for c1, c2, c3 in mat: print(f"|{c1:>2} | {c2:>2} | {c3:>2} |")LikeLike
GeoffR 12:22 pm on 6 August 2025 Permalink |
LikeLike