Magic Squares

Gordon C. Everstine
Gaithersburg, Maryland, USA
g3(at)geverstine(dot)com

One mathematical amusement which has fascinated people for centuries is the magic square, a square array (or matrix) of numbers having the property that the sum of the entries in any row, column, or main diagonal is always the same. For example, a magic square of order 6 is

 31   2   3 34   5 36
 30 26   9 10 29   7
 24 23 16 15 14 19
 13 17 22 21 20 18
 12   8 28 27 11 25
   1 35 33   4 32   6

For this array, the sum of any row, column, or main diagonal is 111. Although magic squares are mathematical curies, their fascination has perhaps resulted from the symmetry and order which they possess. Normally, interest in magic squares is restricted to those formed from the first N2 positive integers, where N is the order (or size) of the square. The reason for this seemingly restricted interest is that squares having negative or fractional numbers offer no additional generality, because such squares can always be transformed into positive integer squares by adding or multiplying every entry by a suitable constant.

A small PC program is available to compute magic squares for any order square between 3 and 2000. Squares of order 2 do not exist. Odd and even order squares must be constructed by different approaches. For odd orders, the program uses a recursive scheme devised by Simon de la Loubère (1642-1729), a.k.a. the Siamese method. For even orders, the program uses the Devedec algorithm. Even orders not divisible by 4 are formed slightly differently from those which are divisible by 4 (doubly even).

The program displays magic squares of order up to 19 on the screen. Larger squares should instead be written to file; each request to write a square to file appends the current square to the end of the file. The correctness of a square may be optionally checked. This check is primarily to verify that the program has not been corrupted during copying or downloading.

For more information about magic squares, see, for example, "Magic Squares and Cubes" by W.S. Andrews (The Open Court Publishing Co., Chicago, 1908; Dover, 1960) and "Mathematical Recreations" by M. Kraitchik (Dover, 1953).

Download Magic Square Program (27KB).

Rev. 20 July 2016