Teaser 2734: Interlocking squares
From The Sunday Times, 15th February 2015 [link] [link]
Place all of the digits 0 to 9 in the grid so that, reading across or down in crossword fashion, one can see a two-figure square, a three-figure square, and two four-figure squares.
What (in increasing order) are the four squares?
[teaser2734]

Jim Randell 11:45 am on 22 March 2022 Permalink |
We can use the [[
SubstitutedExpression]] solver from the enigma.py library to solve this puzzle.The following run file executes in 114ms.
Run: [ @replit ]
Solution: The squares are: 49, 576, 1089, 3025.
(49, 576, 1089, 3025) = (7², 24², 33², 55²).
LikeLike
GeoffR 2:33 pm on 22 March 2022 Permalink |
% A Solution in MiniZinc include "globals.mzn"; % # A # # % B C D E % # F # G % H J # K var 1..9:A; var 1..9:B; var 0..9:C; var 0..9:D; var 1..9:E; var 0..9:F; var 0..9:G; var 1..9:H; var 0..9:J; var 0..9:K; constraint all_different([A,B,C,D,E,F,G,H,J,K]); % sets of 2,3 and 4-digit squares set of int: sq2 = {n*n | n in 4..9}; set of int: sq3 = {n*n | n in 10..31}; set of int: sq4 = {n*n | n in 32..99}; constraint (10*H + J) in sq2; constraint (100*E +10*G + K) in sq3; constraint (1000*A + 100*C + 10*F + J) in sq4 /\ (1000*B + 100*C + 10*D + E) in sq4; solve satisfy; output [ "[A,B,C,D,E,F,G,H,J,K] = " ++ show([A,B,C,D,E,F,G,H,J,K])]; % [1, 3, 0, 2, 5, 8, 7, 4, 9, 6] % [A, B, C, D, E, F, G, H, J, K] % ---------- % ========== % Squares : HJ = 49, EGK = 576, ACFJ = 1089, BCDE = 3025LikeLike
GeoffR 8:10 am on 23 March 2022 Permalink |
A three stage permutation solution.
from itertools import permutations from enigma import is_square digits = set('1234567890') # two digit square HJ for p1 in permutations(digits, 2): h, j = p1 if h == '0':continue hj = int(h + j) if not is_square(hj):continue q1 = digits.difference({h, j}) # three digit square EGK for p2 in permutations(q1, 3): e, g, k = p2 if e == '0':continue egk = int(e + g + k) if not is_square(egk):continue # two four digit squares BCDE and ACFJ q2 = q1.difference({e, g, k}) for p3 in permutations(q2): a, b, c, d, f = p3 if '0' in (a, b): continue bcde = int(b + c + d + e) if is_square(bcde): acfj = int(a + c + f + j) if is_square(acfj): print(f"HJ={hj}, EGK={egk}, ACFJ={acfj}, BCDE={bcde}") # HJ=49, EGK=576, ACFJ=1089, BCDE=3025LikeLike