Recreational Math I: Magic Squares: the “really good” kind

Introduction

ONE OF THE few things you see on the web these days is how to do a really good magic square. There are many websites that tell you about how spiralling arrangements of sequential numbers on a square matrix is magic, but for me, that’s dull. You are limited to doing seemingly less than a dozen such magic squares, so I don’t find them too interesting.

Recall that magic squares are numbers arranged in a square matrix such that each of its rows and columns, and normally both diagonals add up to the same number. Usually, a square of n numbers to a side which has numbers total, will be populated with the entire set of numbers from 1 to n inclusive, in some quasi-random order. These numbers would be arranged in such a manner that the total of each of its rows, columns, and both diagonals equal the same “magic number”, which is different depending on the dimensions of the square. By using random methods suggested in this article, the number of magic squares possible, when n is odd, is equal to (n!)2.

For the 5×5 square, you apparently have to start by moving from the current position to the “top right” square (wrapping to the opposite edge if necessary), and if that square is occupied, move down by 1 square. This non-random, deterministic method apparently works for all squares greater than 5×5 (with odd dimensions).

I read from an old book on recreational math (The Fascination of Numbers, by W. J. Reichmann (1958)), that

  1. Squares of even dimensions (4×4, 6×6) have to be arranged by a different algorithm than squares of odd prime dimension (5×5, 7×7, 11×11, …).
  2. A randomly-generated 5×5 magic square can be made which uses the sum of two matrices.

The number of possible permutations of 5×5 matrices is equal to (5!)2.

Reichmann’s book was the only place where I could find such an algorithm. This seems to be a rare algorithm, even on an internet search. But it is the only method that leads to “magic” results in a variety of ways. These squares seem to be the most robust in terms of the number of ways their “magic” qualities can be determined. They have inspired my writing computer programs that generate such squares as a way of practicing programming several years ago. I have written magic square programs following Reichmann’s algorithm (not sure if he originated it) in VB5, Visual Basic .NET, VB for applications (in Excel), and in Microsoft Quick Basic 4.5. The 16-bit QB 4.5 version does not run on my 64-bit machine, and for similar reasons, neither does the VB5 version, whose runtime DLL is no longer supported by MS Windows 7.

In the next instalments, starting this coming Saturday, I will begin to discuss the making of 3×3 and 5×5 squares, and discuss their magic properties.

Visits: 100