Searching for a Magic Square of Squares

I've wanted to try running software on the GPU for a couple years now, and had been considering ideas like drawing fractals or running neural networks. But after watching a recent Numberphile video on YouTube, I just had to see if I could apply the power to the GPU to searching for magic squares.

 

A "magic square" is a square arrangement of numbers where the rows, columns, and long diagonals all sum to the same value. Trivial examples include, of course, any square like:

555
555
555

where all the values are the same. Generally, we ignore any square containing any repeated digits.

As explained by Matt Parker in the Numberphile video, it is, counter intuitively, easier to find larger magic squares than smaller ones. This example 8×8 magic square he shows was first published in 1890!

56348571847931
332054487295910
264313236438449
195353053124660
152563241245040
655171136583245
611642522713922
446228371451213

Pfeffermann, 1890. All rows, columns, and diagonals sum to 260.

This square also has another property that makes it even more special: it remains a magic square when all the values are squared! All rows, columns, and diagonals sum to 11,180 when the values are squared.

The first known 4×4 magic square of squares was discovered by Euler in 1770:

68²29²41²37²
17²31²79²32²
59²28²23²61²
11²77²49²

Euler, 1770. All rows, columns, and diagonals sum to 8,515.

The Challenge

It's apparently so much harder to find a 3×3 magic square of squares than a 4×4 that nobody has ever done it, and it's possible that none exist. This page has a detailed breakdown of the search.

Toward the end of the video a $10,000 prize was announced for anyone who finds a 3×3 square of squares, but for me it was fun just to see whether a GPU-based program would be faster than a CPU-based one.

After some experimentation with rust and the metal crate, I've got both CPU and GPU solutions working on my Apple Silicon Mac. My algorithm is a simple exhaustive search with "checkpointing" so I can halt and resume the search as needed. The GPU one seems to run about 2.4x faster than the CPU one.

My plan is to run a search with a relatively small maximum root, and then, depending on how long that takes, run another search with a larger maximum root (without repeating any previously examined squares). I've allowed the search to return any "near miss" squares found, where one row or column or diagonal doesn't have the same sum as the rest. I'll list my program's best found squares below.

3×3 Status and "Near Miss" Squares

While searching for magic square solutions, we'll come across many "near miss" squares with one row, column, or diagonal sum that doesn't match the others. I'll list the ones my program finds below. Many of them of course have been previously found, but I'd still like to list them here as my program comes across them. I'll try to omit any squares that mirror or rotate an already listed one.

March 31, 2025:

This one is listed on Mutsumi Suzuki's "Randall's 3x3 semi-magic square of squares" page as having been discovered by Randall Rathbun circa July 1999 (archive.org).

94²113²
127²58²46²
74²97² 82²
Sums of 21,609 with one diagonal sum of 10,092.

April 1, 2025:

188²226²
254²116²92²
148²194²164²
Sums of 86,436 with one diagonal sum of 40,368.

April 2, 2025:

46²82²113²
127²74²
58²97²94²
Sums of 21,609 with one diagonal sum of 16,428.

April 2, 2025:

58²46²127²
94²113²
97²82²74²
Sums of 21,609 with one diagonal sum of 38,307.

April 3, 2025:

Another arrangement of the April 1, 2025 near miss:

92²164²226²
254²148²
116²194²188²
Sums of 86,436 with one diagonal sum of 65,712.

April 3, 2025:

Another arrangement of the April 1, 2025 near miss:

116²92²254²
188²226²
194²164²148²
Sums of 86,436 with one diagonal sum of 153,228.

April 3, 2025:

My exhaustive search with a maximum root of 256 has completed. I am pretty confident there are no magic squares of squares where all the values (roots) are less than or equal to 256.

April 5, 2025:

My little program found the first example near miss Matt Parker shared in the video mentioned above, which was shared with him by (and presumably discovered by) Cheah Xu Heng:

282²339²
381²174²138²
222²291²246²
Sums of 194,481 with one diagonal sum of 90,828.

April 6, 2025:

376²452²
508²232²184²
296²388²328²
Sums of 345,744 with one diagonal sum of 161,472.

October 9, 2025:

I ran the search a fair bit more in April, and a little in July, but none since then. I restarted the search today and found another near miss. I was a bit concerned that I hadn't found any since early April, but this one was spat out after 7 hours today.

This one is also listed on Mutsumi Suzuki's "Randall's 3x3 semi-magic square of squares" page as having been discovered by Randall Rathbun circa July 1999 (archive.org).

62²313²394²
446²218²103²
233²334²302²
Sums of 257,049 with one diagonal sum of 142,572.

October 21, 2025:

Another arrangement of the previous near miss:

103²302²394²
446²233²62²
218²334²313²
Sums of 257,049 with one diagonal sum of 162,867.

October 31, 2025:

Another arrangement of the April 5, 2025 near miss:

138²246²339²
381²222²
174²291²282²
Sums of 194,481 with one diagonal sum of 147,852.

November 13, 2025:

Yet another arrangement of the April 5, 2025 near miss:

174²138²381²
282²339²
291²246²222²
Sums of 194,481 with one diagonal sum of 344,763.

November 20, 2025:

Another arrangement of the April 6, 2025 near miss:

184²328²452²
508²296²
232²388²376²
Sums of 345,744 with one diagonal sum of 262,848.

December 1, 2025:

Another arrangement of the October 9, 2025 near miss:

218²103²446²
313²394²62²
334²302²233²
Sums of 257,049 with one diagonal sum of 465,708.

December 4, 2025:

Another arrangement of the April 6, 2025 near miss:

232²184²508²
376²452²
388²328²296²
Sums of 345,744 with one diagonal sum of 612,912.

February 1, 2026:

My exhaustive search with a maximum root of 512 has completed. I am pretty confident there are no magic squares of squares where all the values (roots) are less than or equal to 512.

Perhaps I am the first to fully search the entire 512 root space (without checking duplicate squares of course).