# 9×9 Magic Squares by the Lo Shu Method

The Lo Shu method generated the only 3×3 magic square that exists (rotations and reversals of the same 3×3 arrangement notwithstanding), and was the first magic square known to be discovered by humans, over 3000 years ago in China. Because of the one magic square it yields, utilizing the Lo Shu method recursively for 9×9 can only generate exactly one 9×9 magic square. A casual glance on Google will tell you that there are many more 9×9 squares out there that break the patterns that we are about to explore.

My preference has always been to discuss algorithms for magic squares that are “high-yielding”, or lead to many distinct magic squares, such as 5×5 (14,400 squares), and 7×7 (over 25 million squares). Why spend an article discussing the one possible square generated by the Lo Shu algorithm? I think this is because this has a great many unique patterns, and there are many “little” squares, each with their own magic numbers. It is not pan-magic in the normal way, but it seems to have multiple magical properties nonetheless.

The basic Lo Shu square begins with an ordered arrangement of the digits 1-9 in a 3×3 matrix:

```                 1  2  3
4  5  6
7  8  9```

Switch each corner number with the number kitty-corner to it:

```                9  2  7
4  5  6
3  8  1```

Then, imagine pressing the 9 to go between the 4 and 2, to create a new row, and doing the same with the 1 in placing it between the 8 and the 6. The diagonal 3  5  7 becomes the middle row of the new square. It would look thus:

```                4  9  2
3  5  7
8  1  6```

The result is a 3×3 square that is magic, and is the only 3×3 magic square of sequential digits 1-9 that exists. Beware of reflections and rotations of these squares, since they are still the same square.

The reason for showing the construction of the 3×3 square is because constructing the 9×9 square follows a strangely identical pattern.

### The 9×9 Lo Shu square is built on the same pattern

The same principle that created the 3×3 square can be used to make a 9×9 square. The drawback is that this method will again only yield one square. In truth, there are thousands of 9×9 squares possible. You begin with the numbers 1 to 81 in sequence in a 9×9 array:

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

Let’s look at the first column. We make a 3×3 array out of this, starting by placing the numbers in numerical order in the same manner done with the numbers 1 to 9 earlier:

```                         1   10   19
28   37   46
55   64   73```

Then, we switch the corner numbers again:

```                       73   10   55
28   37   46
19   64    1```

Form new rows as described earlier, resulting in the top being 28  73  10, and the bottom being 64  1  46, with 19  37  55 being the middle row:

```                       28   73   10
19   37   55
64    1   46```

The result is a 3×3 sub-square that itself is magic. You can repeat this for the second column:

```                       29   74   11
20   38   56
65    2   47```

But then you would notice that each cell in this new 3×3 sub-square is one more than each corresponding cell in the previous 3×3 sub-square. Thus, the remaining sub-squares can be obtained by adding 1 to the previous sub-square when doing each of the columns in order from the original 9×9 square. You get the following intermediate 9×9 square:

 28 73 10 29 74 11 30 75 12 19 37 55 20 38 56 21 39 57 64 1 46 65 2 47 66 3 48 31 76 13 32 77 14 33 78 15 22 40 58 23 41 59 24 42 60 67 4 49 68 5 50 69 6 51 34 79 16 35 80 17 36 81 18 25 43 61 26 44 62 27 45 63 70 7 52 71 8 53 72 9 54

OK, so we are not quite there yet. The light grey and white patterns denote the nine 3×3 sub-squares that we were just discussing. But in the manner done for the initial 3×3 squares, we need to:

1. Switch out the corner 3×3 sub-squares, as shown below.
 36 81 18 29 74 11 34 79 16 27 45 63 20 38 56 25 43 61 72 9 54 65 2 47 70 7 52 31 76 13 32 77 14 33 78 15 22 40 58 23 41 59 24 42 60 67 4 49 68 5 50 69 6 51 30 75 12 35 80 17 28 73 10 21 39 57 26 44 62 19 37 55 66 3 48 71 8 53 64 1 46
2. Finally, make the magic square from the sub-squares going diagonally. That is, make a top row of the three sub-squares in the top left corner; then make a bottom row of the three sub-squares in the bottom right corner. The middle rows of the 9×9 square will consist of the three sub-squares extending from the bottom left to the top right. In this manner, we would have formed the magic square in the precise pattern that we used for individual numbers when we did the original 3×3 square. Below is the square, revelaling the magic number totals on the rows, columns, and diagonals:
 31 76 13 36 81 18 29 74 11 369 22 40 58 27 45 63 20 38 56 369 67 4 49 72 9 54 65 2 47 369 30 75 12 32 77 14 34 79 16 369 21 39 57 23 41 59 25 43 61 369 66 3 48 68 5 50 70 7 52 369 35 80 17 28 73 10 33 78 15 369 26 44 62 19 37 55 24 42 60 369 71 8 53 64 1 46 69 6 51 369 369 369 369 369 369 369 369 369 369 369 369

The feature of this square that intrigued me was in the way the algorithm was scalable from 3×3 to 9×9. That made it easy to learn.

# 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.

 A B C D E F 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:

 A B C D E F 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:

 A B C D E F 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:

```=IF(AND(A1=A6;B1=B6;C1=C6;D1=D6;E1=E6;F1=F6);"TRUE";"FALSE")
=IF(AND(A2=A5;B2=B5;C2=C5;D2=D5;E2=E5;F2=F5);"TRUE";"FALSE")
=IF(AND(A3=A4;B3=B4;C3=C4;D3=D4;E3=E4;F3=F4);"TRUE";"FALSE")```

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:

 A B C D E F K L M N O P 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:

 E F G H I J 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:

R 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:

 C D E F G H I J K L 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 14 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 …