RECREATIONAL MATHEMATICS · MAGIC SQUARES

Magic, Bimagic & Trimagic TXT Checker

Exact sums of entries, squares and cubes. Rows, columns and diagonals.

Inder J. Taneja

1. Expected sums for a normal square

For entries 1 to n². These formulas give expected sums; they do not verify a square.

2. Check a TXT file

Select a numbers-only square. Spaces, tabs, line breaks, commas and semicolons are accepted. Titles, row labels and appended sums must be removed. Order is inferred from the total entry count; line breaks do not define rows.

Your file is processed on your device.
Two streaming passes avoid storing the full square. Exact BigInt arithmetic protects large sums. Large files can take several minutes. Repeated entries are checked independently of magic, bimagic and trimagic sums. Upload the extracted TXT matrix, rather than a ZIP or numbered archive part. A compact bitset covers values 1 to n² for up to 500 million entries; up to one million other distinct values are tracked. Any incomplete repetition check is clearly reported.

What is checked?

Magic: all rows, columns and both main diagonals have one common sum. Bimagic: the square is magic and the same lines also have a common sum after every entry is squared. Trimagic: all these conditions hold and the same lines have a common cube sum.

Pandiagonal: the square is magic and all n wraparound diagonals in each direction have that common sum. Pandiagonal through power 2: bimagic sum tests and all wraparound sums pass for powers 1 and 2. Pandiagonal through power 3: trimagic sum tests and all wraparound sums pass for powers 1, 2 and 3. A trimagic square need not be pandiagonal.

Wraparound ↘ line k + 1 has c − r ≡ k (mod n); wraparound ↙ line k + 1 has c + r ≡ k (mod n), with zero-based r and c. Main diagonals are shown separately as ↘ and ↙.

Included trimagic example

The order-16 example is credited to Chen Qinwu and Chen Mutian, 2005, as reproduced in Mikael Hermansson’s Squaremagie compilation, square (1), page 1. Its constants are S₁ = 2056, S₂ = 351576 and S₃ = 67634176.