4 × 4 · Magic sum S
A 4×4 magic square with your chosen sum
Choose an integer sum and discover two ways to build a magic square
Choose an integer sum and discover two ways to build a magic square
Decomposition of the chosen number
Magic sum:
Verification
Why is this square special?
These configurations also sum to 34 in the starting square. Each contains exactly one special cell, so after the transformation it sums to S.
Why does it work?
The numbers 13, 14, 15 and 16 occupy one special cell in every row, column and diagonal. If D = S − 34 = 4q + r, each line gains 3q + (q+r) = D and therefore sums to S. Euclidean division also works when D is negative.
For S below 34, zero and negative entries may appear; all sixteen entries remain distinct. A birthday gift is only one possible use of this square.
Source of inspiration: Arthur Benjamin and Michael Shermer, Secrets of Mental Math: The Mathemagician’s Guide to Lightning Calculation and Amazing Math Tricks, Magic Squares section, pp. 206–209 in the cited edition. The explanation and code are original.
The trick is to write the chosen number as S = 21a + b. The sixteen cells are linear combinations of a and b designed so that every row, every column and both main diagonals automatically have the same sum.
First row: (a+b) + a + 12a + 7a = 21a + b = S.
Second row: 11a + 8a + b + 2a = 21a + b = S.
Show symbolic checks for every row, column and diagonal
A correct magic sum does not guarantee sixteen positive, distinct entries: the program checks these properties separately.