Knowledge Node - Magic Squares

return to Knowledge Node index

Magic Squares are matrices where the sum of each row, column, and main diagonal are the same number.

I first learned about them in 9th grade.  The class was given a handout that incorrectly claimed that there exists only eight 3x3 magic squares, and it also falsely claimed that the number of 4x4 matrices was unknown.  I challenged myself to find the total of 4x4 matrices. To date I've written six different computer programs to solve the problem, each using a different method or algorithm to search.  I'd like to announce that I solved the number of 4x4's nearly a year ago, and I've been trying to solve the number of 5x5's, but I've run into some problems.  Below are some examples of 4x4 matrices.

Unfortunately solving the 4x4's wasn't as big of a deal as I thought it would be.  I later found out that many mathematicians have already found that there are 880 unique 4x4 magic squares. I eventually found 7,040 4x4 magic squares.  Reflections and 90-degree rotations on a two-dimensional plane can cause the total number of possibilities to be multiplied by eight.  880 unique matrices * 8 similar forms = 7,040 total possible magic squares.  Thus, I have succeeded and found experimentally the total number of 4x4 magic squares!  Download them all.

Just how many possible matrix arrangements are there for a 4x4 matrix?  The total number of ways to arrange 16 numbers is 16! (factorial), exactly 20,922,789,888,000 permutations to check, a LOT!  That's why finding the number of 4x4's was so difficult.  The big problem in solving the 5x5 is that there are 25! arrangements, or 15,511,210,043,330,985,984,000,000.  I honestly don't have the slightest idea how to even pronounce that number.

On my Pentium 4, 1.7 Ghz laptop, I can find the 4x4's in about a minute.  Unfortunately, using my fastest algorithm finding the 5x5's will take approximately 741,354,768,000 times longer! That means I'll be waiting for about 1,409,557 years.  I better hope for some faster computers!

just curious... added 5/4/04

Some interesting references:

return to Knowledge Node index


return to the main page