Classic Mathematical Recreations

Copyright © G. P. Jelliss 2002 (updated May 2003)

Magic Rectangles

The basic problem is: To arrange the numbers 1 to mn in an array of m ranks and n files so that each rank adds to the same total M and each file to the same total N.

The totals M and N are termed the magic constants. Since the average value of the numbers is A = (mn + 1)/2, we must have M = nA and N = mA. The total of all the numbers in the array is mnA = mM = nN. If mn is even mn + 1 is odd and so for M = n(mn + 1)/2 and N = m(mn + 1)/2 to be whole numbers n and m must both be even. On the other hand if mn is odd then m and n must both be odd, by simple arithmetic. Therefore: An odd by even magic rectangle is impossible.

When m = n we have a magic square and the rank and file totals are the same magic constant M = nA = n(1 + n²)/2. Some square solutions have the extra property that the two main diagonals also add to the magic constant; we call them diagonal magic squares. For some values of n it is also possible to construct pandiagonal magic squares in which the shorter diagonals are joined up in pairs to make broken diagonals each with n numbers like the main diagonals and also adding to the magic constant. A rectangle in which only the ranks but not the files, or only the files but not the ranks, add to a constant value are naturally termed semimagic.

[Note: some writers on "magic squares" use the term to mean diagonal magic squares, and they sometimes refer to squares that do not have the diagonals magic as "semimagic". These usages should be avoided since the above definitions are more generally applicable.]

Permuting the ranks or files of a magic rectangle, or transposing them so that files become ranks and vice versa, does not affect the uniform-sums property, so the transformed rectangle is still magic. Thus (excluding the trivial 1×1 case) an m×n magic rectangle is one in a set of 2m!n! magic rectangles. Eight of these will be the rotations and reflections of the given array. These factorial products rapidly increase. For example, from one 6×6 array we derive 2×6!×6! = 1,036,800 arrays and we are already over a million. We must therefore be more selective in the cases we study.

Pairs of numbers adding to 2A are called complementary. The reverse numbering replaces each number r by its complement 2A–r. Thus any set of k entries with average A (adding to kA) will be replaced by a set of k entries with average 2A–A = A, still adding to kA. Therefore: The reverse of a magic numbering is also magic. In some cases the reverse of a numbered array is simply the same array reflected or rotated. This occurs when the numbering is symmetric. This is shown by the complementary pairs being the same distance on either side of the axis or centre of symmetry.

Thinking of the numbers as marking the movement of a piece across a rectangular board, an interesting restriction is to keep the number of different types of move used to a minimum. For convenience we can take m < n so that the rectangles are lengthwise across the page. Then we can call a magic rectangle a magic tour if the number of different move-types used in it is < m. If more are used the magic rectangle becomes a magic tangle!


Magic rectangles 2×n

The simplest example of a magic rectangle is the 2×4 shown here, which is a magic king tour, using only {0,1} and {1,1} steps; there is also a magic king tour on the 2×6 board, four on the 2×8 board, and 10 on the 2×10. By permuting the columns we can also obtain magic tours using {0,1} and {1,2} moves [3 on 2×4, 11 on 2×8], {0,1) and {1,4} moves [8 on 2×8], and {0,1} and {1,5} moves [1 on 2×8]. Surprisingly the king moves are the only ones that work magic on the 2×6.
1764
8235
1113987
12210456

Magic rectangles 3×n

A solution to the 3×3 case has been known since about 2200BC in China [F. M. Müller Sacred Books of the East vol.XVI (The Yi-King) Oxford University Press 1882.] It uses three types of move: {0,1}, {1,1} and {1,2}, and is symmetrical. This magic square also has a property of completeness lacking in any other magic square, namely every possible combination of numbers adding to the magic constant 15 occurs in the 8 lines of the diagram.
294
753
618
5144710
1318153
6912211
I show also a 3×5 magic (rec)tangle. This (and its permutes) are the only 3×5 magic rectangles that are "self-complementary" in the sense that the reverse tour is a permute of the given tour. This property permits symmetry. Four geometrically distinct symmetric solutions are possible; the one shown uses four types of move {0,2}, {1,1}, {1,2}, {2,3}.

Magic squares 4×4

Many people studied magic squares during the middle ages. But the first to list all 880 of the 4×4 diagonally magic squares was B. Frénicle de Bessy. They were published after his death by P. de la Hire Divers Ouvrages de Mathematique et de Physique par Meisseurs de l'Academie des Sciences 1693. The first diagram shows the only one that uses just two different move-types {0,1} and {1,2}:
114712
813211
94156
163105
112516
147103
112156
81349
The second diagram above shows a magic square using {0,3} and {1,2} moves. This is not magic in the diagonals, but has other interesting properties instead. First its move-pattern (if 16 is joined to 1 to make a closed tour) has two axes of symmetry [it is one of 11 tours with this property]. Second it can be cyclically renumbered and retain its magic properties [change 5 to 1, 6 to 2, ..., 16 to 12, 1 to 13, ... , 4 to 16].


Magic squares 5×5

The 3×3 diagonally magic square uses three types of move {0,1}, {1,1} and {1,2} within the boundaries of the square. However, if we think of the board as having its top and bottom edges joined (to make a tube) and the left and right edges (the ends of the tube) joined to make a torus, these moves can be interpreted differently. The simplest way is to interpret them as a series of diagonal {1,1} steps interrupted by {0,1} steps. However it can also be interpreted as {1,1} steps interrupted by {0,2} steps (going the other way round the torus), or as {1,2} steps interrupted by {0,1} steps, or as {1,2} steps interrupted by {0,2} steps.

I call this process the step-sidestep method. The first type of move, the step, is the main type of move used. The sidestep move is interpolated whenever the next main step would take the touring piece to an already visited cell. This method is effective in generating magic tours on any square boards of an odd number of cells, and various combinations of generative steps can be used. The following four different 5×5 diagonally magic tours are generated by the same pairs of steps that generate the 3×3 square. Diagonal magic can always be achieved, after completing the tour, by "rotating" the torus (more accurately, circularly permuting the ranks or files) to bring the middle number (the average, A, which in this case is 13) to the centre cell, since the other numbers on the diagonals are then complementary pairs.
11182529
101219213
46132022
23571416
17241815
11247203
41225816
17513219
101811422
23619215
17625143
11519822
102413216
41872115
23121209
23571416
11182529
46132022
17241815
101219213


Magic squares 8×8

On the 8×8 board the magic constant is 260, i.e. 8×(64 + 1)/2. The first published solution using a single type of move, that of the knight, was by William Beverley Philosophical Magazine 1848, as shown here.
William Beverley 1848
13047525284354
48512294453627
31464942585542
50332455641267
336215209243958
1619346140571023
6314173621125938
1835641360372211
Carl Wenzelides 1858
24350254863623
51261445244762
28342496445227
41522742186146
142940533659209
3954133217103560
3015563712335819
5538311657181134
A solution with the two main diagonals also adding to 260 is believed to be impossible, though a complete proof of this has never been given. [Note: A number of authors state that magic knight's tours of the chessboard were constructed by Euler, but this is a mistake. Euler presented an important paper on knight's tours (in 1759), but his results concerned methods of construction and forms of symmetry, none of his tours was magic.]

How many 8×8 magic knight's tours are there? The answer to this depends on how we count them.

The number known since January 2003, when T.S. Roberts discovered 2 new geometrically distinct cases, is 266 generic arithmetical solutions. Each of these can appear in eight different orientations by "rotation" and "reflection", (keeping the numbers the right way up), so that there are 8 × 266 = 2128 magic knight's tour arrays. However, the reverse of a magic tour, formed by replacing the numbering 1, ..., 64 by 64, ..., 1 is always magic. So the 266 solutions occur in pairs that are reversals of each other. We may therefore say that there are 133 magic knight's tour paths, each of which can be numbered from either end. There is yet another complication: some of these 133 paths are reentrant, that is the cell numbered 64 is a knight's move from the cell numbered 1, and some of these paths can be renumbered, in one or more ways, by a cyclic shift that leaves the square magic. There are 13 "closed tours" of this type, generating 43 reentrant magic tours. [The tour by Carl Wenzelides shown above is of this type, remaining magic under a cyclic shift of 16. It is also the only such cyclic tour that is also symmetric (when considered as a closed path). This is shown numerically by diametrally opposite cells having a fixed difference of 32.] Thus (taking 133 – (43 – 13)) we may say that there are 103 geometrical forms of magic knight's tour of the chessboard. Thus those who prefer small numbers will say there are 103 distinct solutions, while those who think big numbers impressive will say there are 2128, and they could both be right.


Back to: Index of RecreationsGPJ Index Page