Teaser 3185: Multiple squares
From The Sunday Times, 8th October 2023 [link] [link]
My grandson likes to compile 3×3 magic squares, where each of the three rows of numbers, each of the three columns of numbers and both of the straight diagonals, add up to the same total. This he did without repeating any of the nine numbers in the square.
He has now progressed to compiling similar 3×3 squares, which instead of the eight rows, columns and diagonals of numbers adding to the same total, they instead multiply to produce the same product.
In his first such square this product was 32,768. He was able to find every square of nine different whole numbers that gives this product, excluding identical rotational and mirrored squares.
What, in ascending order, were the totals of the nine numbers in each of his different squares?
[teaser3185]
Jim Randell 5:09 pm on 6 October 2023 Permalink |
32768 = 2^15, so each multiplicative square is filled with numbers that are powers of 2. And we can treat it as an additive magic square of the corresponding exponents.
So we just need to find how many essentially different additive magic squares there are (modulo rotation and reflection) with a magic constant of 15. And we can then transform the exponents back to powers of 2 to give the required answers. (Note we allow an exponent of 0 to give a corresponding value of 2^0 = 1).
This Python program uses the [[
SubstitutedExpression()]] solver from the enigma.py library to generate all possible additive magic squares of exponents, and then collects those that are different, and we then transform the exponents back to powers of two and sum the numbers in the corresponding multiplicative magic square to give the required total.It runs in 77ms.
Run: [ @replit ]
from enigma import (SubstitutedExpression, irange, uniq, printf) # orientations of a square squares = [ # rotations (0, 1, 2, 3, 4, 5, 6, 7, 8), (2, 5, 8, 1, 4, 7, 0, 3, 6), (8, 7, 6, 5, 4, 3, 2, 1, 0), (6, 3, 0, 7, 4, 1, 8, 5, 2), # reflections (2, 1, 0, 5, 4, 3, 8, 7, 6), (8, 5, 2, 7, 4, 1, 6, 3, 0), (6, 7, 8, 3, 4, 5, 0, 1, 2), (0, 3, 6, 1, 4, 7, 2, 5, 8), ] # find the canonical form of a square def canonical(sq): return min(tuple(sq[j] for j in js) for js in squares) # find possible squares p = SubstitutedExpression( [ # rows "A + B + C == 15", "D + E + F == 15", "G + H + I == 15", # columns "A + D + G == 15", "B + E + H == 15", "C + F + I == 15", # diagonals "A + E + I == 15", "C + E + G == 15", ], base=11, answer="(A, B, C, D, E, F, G, H, I)" ) # collect results ts = list() # find different squares for sq in uniq(canonical(sq) for sq in p.answers(verbose=0)): # transform the powers to numbers, and sum them t = sum(2**n for n in sq) printf("[{sq} -> {t}]") ts.append(t) # output solution printf("totals = {ts}", ts=sorted(ts))Solution: The totals of the numbers in the different squares are: 1022, 1533, 1911.
And the corresponding squares are:
LikeLike
Hugo 9:26 am on 15 October 2023 Permalink |
If we halve each number in the first of those squares, we get one with magic product 4096.
But that’s certainly not the smallest possible value, as Dudeney showed:
see the solution and comments to Puzzle no. 203.
LikeLike