Another crack at 6×6 magic squares

Even-ordered magic squares are not difficult just because they are even, in my opinion. They are difficult to design because their order is composite. My experience has shown that by far the easiest to design are magic squares whose order is a prime number like 5, 7, 11, or 13. I have run into similar problems with 9×9, 15×15, as well as 6×6 and 8×8. The 6×6 seems to have the reputation for being the most difficult to make magic, although I have stumbled on one system that produced them, and wrote about it a few years ago, about how I applied that method to a spreadsheet. That method, however, led only to 64 possibilities.

Spreadsheets are a great way of checking your progress as you are building such squares, especially when you are trying to build a square using, say, a method you made up on your own, such as applying a Knight’s tour (which works OK with an order-8 square) to an order-6 square. This would require some facility with using spreadsheet formulae and other features which improve efficiency. Using your own method is very much based on trial and error, and you have to make a rule as to whether you will be wrapping the Knight’s moves (if you decide to use a Knight’s tour) to the opposite side of the board, or will you be keeping your moves within the board limits, changing direction of the “L’s” in your movements (this seems to lead to dead ends as you find you have no destinations left which follow an “L”, and consequently, squares which are not really magic). At any rate, the best squares follow some kind of rule which you need to stick to once you make it.

The best ones I have been able to make with a knights tour are: 1) when your L’s are all in the same “direction”‘ 2) when you sum up two squares. The problem is, all of the ones I have made with these methods so far either end up with weak magic (rows add up but not the columns) but the numbers 1-36 are all there; or all rows and columns make the magic number of 111, yet not all of the numbers are present and there are several duplicated (and even triplicated) numbers.

1 9 17 24 28 32 111
26 36 4 7 15 23 111
17 19 27 32 6 10 111
34 2 12 17 19 27 111
21 29 31 4 8 18 111
12 16 20 27 35 1 111
132 111 111 111 111 111 111 90

The above table shows the totals for the rows and columns for one attempt I made for a semi-magic square. Rows and columns work out to the correct total, but not the diagonals, as shown by the yellowed numbers. There are also duplicate entries, as well as missing entries. 1, 4, 12, 19, and 32 have duplicates, while there are three of 17 and of 27. Numbers missing are 3, 5, 11, 14, 22, 25, 30, and 33. That being said, the rows and columns add perfectly to 111, but not the diagonals. However, the average of the diagonals is the magic number 111 (this does not always work out). The sum of the missing numbers is 156, while the sum of the “excess” numbers (the sum of the numbers that occur twice plus double the sum of the numbers occurring thrice) is also 156 (could be a coincidence).

The above semi-magic square results from the sum of two squares where a knight’s tour is performed with the second square where the numbers 1 to 6 go in random order going down from top to botton. If I am too close to the bottom edge of a column, the knight’s tour wraps back to the top of the square. Beginning on the third column, I shift the next entry one extra square downward. The result is 6 of each number, each of these unique to its own row and column.

The first square are the multiples of 6 from 0 to 30 in random order going from left to right, also in a knight’s tour, wrapping from right to left and continuing. The third row is shifted by 1 to the right.

0 6 12 18 24 30
24 30 0 6 12 18
12 18 24 30 0 6
30 0 6 12 18 24
18 24 30 0 6 12
6 12 18 24 30 0
1 3 5 6 4 2
2 6 4 1 3 5
5 1 3 2 6 4
4 2 6 5 1 3
3 5 1 4 2 6
6 4 2 3 5 1

Note that the first square wasn’t really randomized.  When I tried to randomize it, the result was still semi-magic, similar to what was described. In the case I attempted, the average of the diagonals was not 111. The two are added, this time using actual matrix addition built into Excel. There is a “name box” above and at the far left of the application below the ribbon but above the spreadsheet itself. This is where you can give a cell range a name. I highlighted the first square with my mouse, and in the name box I gave a unique name like “m1x” (no quotes). The second was similarly selected and called “m2x”. I prefer letter-number-letter names so that the spreadsheet does not confuse it with a cell address (which it will). Then I selected a 6×6 range of empty cells on the spreadsheet and in the formula bar (not in a cell) above the spreadsheet (next to the name box), I entered =m1x+m2x, then I pressed CTRL+ENTER. The range of empty cells I selected is now full with the sum of the squares m1x and m2x, which is the first semi-magic square shown in this article.

How to make a 6×6 magic square using a spreadsheet

You may think that, the way I offer instructions here, that I could make this article shorter. And you can make this less work: just take out all the safeguards and self-checks that I have programmed into this spreadsheet, and you are back to something close to a pencil-and-paper experience.  If you are actually using pencil and paper, and plan to make more than a few, be prepared to go through a lot of paper.

I use Apache Open Office as the spreadsheet, and I can assure you that the same commands work in Excel. There are a lot of commands to invoke, but once they are set, you need only modify 12 different numbers on one of the preliminary squares if you want to change anything. So, while it’s a bit of work, it is rewarding in the end. There are also several shortcuts to forula making that save work, but in one part of the operation, the construction of the second preliminary magic square there are no shortcuts that I am aware of. But after all that work, you have a constructed a system by which a good number of the de la Hire squares can be made. I say “a good number”, since there are two methods which seem to be attributable to de la Hire: one described by Clifford Pickover in his book The Zen of  Magic Squares, Circles and Stars, and another in a PDF I found on the internet originating from the King Fahd University of Petroleum and Minerals, located in Saudi Arabia. While the PDF cites Pickover in the referece section, both methods of construction which are attributed to de la Hire are quite different. This article favours the King Fahd method. The King Fahd method is likely a simplification, but it works well. Pickover’s is more open-ended, and one would need to fiddle with it a lot more to get it to work.

I don’t give mouse-based or keyboard-based shortcuts in this article, since it would make this article even longer. I suggest that you need some familiarity with your chosen spreadsheet and its shortcuts to make this process a lot easier.

The idea is that the magic square we want is the sum of two preliminary 6×6 squares. The first square, as in the odd-ordered square, consists of the numbers 1 to 6. Both main diagonals must contain the magic numbers 1 to 6 in sequence, increasing from left to right.

1 1 6
2 2 5
3 3 4
4 3 4
5 2 5
6 1 6

Next, you work in columns. The values in the last 3 columns are dependent on the values of the first 3 columns. The first and last column are dependent, and in the first column you arrange random 6s and 1s so that there are 3 of each. The last column is an anti-reflection, in that a 1 appears in a cell of the last column if a 6 appeared in a corresponding cell in the first column. In case you want to change your square around, you can get the spreadsheet to do this by placing an =IF function in the cells of the last column. For cell F2, you can type the formula: =if(a2=6,1,6). If you are using open office, use semicolons in place of commas. This says that if the value in A2 is 6, then place a 1 here, othwerwise place a 6 here. This formula can be repeated for cells F2 through F5, changing “a2” to the corresponding cell.

Your square might now look something like this:

1 1 6
2 6 2 5 1
3 1 3 4 6
4 6 3 4 1
5 6 2 5 1
6 1 6

We may consider 1 and 6 as being complementary pairs. Similarly, 2 and 5 are another such pair, while 3 and 4 are a third. Notice that the last column consist of nothing but the complement of the first column. In every corresponding row, a 6 is exchanged for a 1, or a 1 for a 6. You proceed similarly for the other four columns. For column B, you need three 5s and one 2. Column E will have their complements, possibly by inserting =IF() statements in the blank cells. Proceeding similarly for columns C and D, you get something like:

1 1 5 3 4 2 6
2 6 2 4 3 5 1
3 1 2 3 4 5 6
4 6 5 3 4 2 1
5 6 2 4 3 5 1
6 1 5 4 3 2 6

Now, check to see if there are duplicate rows. This should be somewhat easy to spot, but if you want this to be auto-detected, you can use formulas. My experience tells me that you ought to watch out for certain pairs of rows: rows 1 and 6, rows 2 and 5, and rows 3 and 4. You may set up an =IF() to check this. Outside of your square, type:


one command in each cell. If everthing goes right, each of these statements sould say “FALSE”. If anything reads as “TRUE”, then duplicate rows exist. In the above square, rows 2 and 5 are duplicated. Switching the values in A2 and A3 was enough to fix that problem. The square, along with the second square, is shown below:

1 1 5 3 4 2 6 FALSE 0 0 30 30 30 0
2 1 2 4 3 5 6 FALSE 24 6 6 24 6 24
3 6 2 3 4 5 1 FALSE 12 18 12 12 18 18
4 6 5 3 4 2 1 18 12 18 18 12 12
5 6 2 4 3 5 1 6 24 24 6 24 6
6 1 5 4 3 2 6 30 30 0 0 0 30

The three “FALSE”s above are from the =IF() statements shown above which assure that there are no repeated rows in the first square.

The second square. written in columns K through P, is merely the consequence of the first square. It contains multiples of 6 from 0 to 30, but whose values are the products of the first square, as a matrix which has been turned on its side. The first row of this new square are derived from column A of the first square. If we let n be any row of the first matrix, then the first row shall take on the value given by the spreadsheet formula =(An – 1)6, replacing n with the numbers 1 through 6. These formulas occupy the first row of the new matrix. For example, M1 can take the formula =(A3 – 1)6.

The second and subsequent rows of the new matrix are thus derived from values of the corresponding columns of the first matrix. N5 would have the formula =(E4-1)*6 typed into it. And if you construct the square this way, it is rewarding once it’s done, since you only need update the 12 numbers in the first 3 columns of the first square; the ones which omit the diagonal numbers. The rest of the spreadsheet will figure everything out in real time. So, in my opinon, it’s worth the slight tedium, and takes only a few minutes of concentrated effort.

Now, we can add the squares. To do this, you need a third square, which will be the matrix sum of the first two. Place the square in an out-of-the-way location, such as below the first two, and in those cells, enter your sums. The first row and column should contain (in consistency with my example) the formula =A1+K1. This goes on until the last row and last column, which contains the sum: =F6+P6. The last square then probably looks something like this:

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

Now, we need to do a sanity check. Did we actually get all numbers from 1 to 36? You can sit there and hunt around, but since we have a spreadsheet, we can lay out the numbers 1-36 in sequence in one column from R1 to R36, and in the next column do a =countif() to the absolute cell addresses $E$8:$J$13. The countif command in cell S1 would be: =countif($e$8:$j$13, R1), and for cell S22 would be: =countif($e$8:$j$13, R22).The resulting columns under R and S:

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

Column R contains the numerical value, and column S is the frequency that number appears in the magic square. The 1 in that column assures us that we have the right number of each of the 36 numbers. A “2” or a “0” ought to worry us, since that tells us there are duplicates or missing numbers. But it looks like we’re doing just fine.

Now finally to check for magic. The first row of the magic square is row 8, so place this formula in L8: =SUM(E8:J8). Do this for each row. The cell ranges represent the corresponding row. Under L13, we type: =SUM(E13:J13), for example. All values should equal 111.

The columns also get this treatment: cell E15 gets the formula: =SUM(E8:E13). Do this for all columns. Column J should receive the formula =SUM(J8:J13) in cell J15. All sums should equal 111.

The diagonals are a little more picky, since they are not really amenable to a =SUM() command, and they are not tangible cell ranges. So, the formula: =E13+F14+G15+H16+I17+J18 is placed in cell L15 for the left-to-right diagonal which slants down. The other diagonal has the formula =e13+f12+g11+h10+i9+j8 placed in cell C15.

This all results in the following arrangement:

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

The 111’s tell us that we have achieved the magic sum in all rows, columns and both diagonals. The King Fahd variant appears to allow for only 43 = 64 magic squares out of the thousands that are possible, and even then, not all of them work. Pickover’s method may lead to 4096 possibilities, but it would appear that most of them are dead ends, making the latter variant more difficult to work with.

The de la Hire method is not the only method that exists. 24 more squares are possible using the “Magic Carpet” method elucidated by the Grogno website. Many methods such as Magic Carpet conceive of the square as a collection of smaller squares, and the method fpr their construction appear to be non-random. de la Hire can be used on all singly even magic squares. From what I have been able to find there appears to be no truly random method for constructing singly even squares such as 6×6 as there was for 5×5, 7×7, and other odd-ordered magic squares.

My first 6×6 magic square

There are two kinds of even-ordered magic squares. Singly-even and doubly-even. Doubly-even magic squares have its dimensions divisible by both 2 and 4. Thus, they have dimensions that are multiples of 4. Singly even magic squares are only divisible by 2 and not 4. They include 2, 6, 10, 14, 18, 22, and so on.

For my first ever even ordered magic squares, I for some reason chose the most difficult squares to construct, and these are squares of singly even order. In fact, I have to be so careful to watch out for all possible things that can go wrong, that I have to set up a spreadsheet to verify the details for me that can be non-trivial to spot. Such as:

  • duplicate numbers, which can take a while to spot
  • missing numbers, which go hand-in-hand with the first problem (the numbers in this square should be from 1 to 36, with no skips or repeats)
  • duplicate lines in one of the preliminary squares used in the sum
  • sums not adding to 111, the magic number for this kind of square

I can do odd-ordered squares in my sleep, but the construction of singly-even ordered squares are not as straightforward, since they appear to have random and non-random elements in them. In fact, the best constructions I have heard of (namely the method devised by Philippe de la Hire (1640-1719)) makes most of the square very deterministic, and much less random than we saw for 5×5 and 7×7.

Not all of the “random” elements in 6×6 squares work, and it looks as if one has to just try out different combinations. Following instructions may always lead to squares with the magic number in all of the required rows, columns and diagonals, but it still may suffer from the pitfalls mentioned above.

It took me several weeks of trial and error before I could make one that I could share. For the first while I wasn’t looking for duplicate lines in the preliminary squares, but after that plus a few other modifications to the method, pure magic squares were being produced.

I will leave the construction of the magic square in the next blog article, but here is a square I made using these methods:

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

To be continued …