I have found a slightly easier way to generate panmagic squares than the one described in Part 1. This method generates essentially the same squares, but the steps are easier to follow. It is described here.
Start by placing a 1 directly below the center square. (As this is a panmagic square, the initial placement does not matter, but this particular position gives the square an additional property. It will be covered after the square is generated.)
Start by placing a 1 directly below the center square. (As this is a panmagic square, the initial placement does not matter, but this particular position gives the square an additional property. It will be covered after the square is generated.)
Squares that have been filled in during the current step are highlighted yellow.
Next, go 2 squares to the left and 1 square down from where the 1 was just placed and put a 2 there. Continue making these knight's moves and placing cells until you are back where you started. If you go out of the bottom of the square, go to the top, and vice versa. The same applies for left and right. For example, the 2 is at the bottom-right corner, so when you move over 2 cells, it wraps around to the left side, and going 1 cell down brings it to the top.
Next, go 2 squares to the left and 1 square down from where the 1 was just placed and put a 2 there. Continue making these knight's moves and placing cells until you are back where you started. If you go out of the bottom of the square, go to the top, and vice versa. The same applies for left and right. For example, the 2 is at the bottom-right corner, so when you move over 2 cells, it wraps around to the left side, and going 1 cell down brings it to the top.
Now, move down 2 cells from the cell that was last placed and write the next number - in this case, 6 - in that cell.
Repeat the knight's move procedure until the cell that you want to place a number in already has a value in it. In this case, the interfering cell will be 6.
Continue in this way. Make knight's moves until a cell overlaps, go 2 cells down and repeat until the square is filled.
The final product should look like this:
The reason that the 1 was placed below the center is that it puts the cell with the median value - in this case, 13 - in the center of the square. Because of this, any 2 cells that are in opposite locations on the square (e.g. 16 and 10) add up to the same number, 26. This type of square is called an associative magic square.
This method of creating a magic square is a variant of what is called the Siamese method. In the Siamese method, the cells continue in a line until there is overlap, jump to a new line, and repeat until the square is filled. The jump between cells when there is no overlap is called the normal vector, and the jump when there is overlap is called the break vector.
In the square above, the normal vector is the knight's move, represented by (2, 1), and the break vector moves 2 cells down, or (0, 2). I am considering the top-left corner to be the origin, which may sound a little bit strange, but it is because this is what Processing and other languages use.
I have not found this particular variant online, and the only variant that I have found that generates panmagic squares is that with ordinary vector (2, 1) and break vector (1, -1) (http://mathworld.wolfram.com/MagicSquare.html). However, with this method, squares whose orders are multiples of 3 are invalid, meaning that numbers overlap. In the method that I have found and described above, squares whose orders are multiples of 3 are still magic, albeit not panmagic. For the 9x9 square, which has a few properties other than being magic, see Part 2.
The image above was generated with the following Processing program.
This method of creating a magic square is a variant of what is called the Siamese method. In the Siamese method, the cells continue in a line until there is overlap, jump to a new line, and repeat until the square is filled. The jump between cells when there is no overlap is called the normal vector, and the jump when there is overlap is called the break vector.
In the square above, the normal vector is the knight's move, represented by (2, 1), and the break vector moves 2 cells down, or (0, 2). I am considering the top-left corner to be the origin, which may sound a little bit strange, but it is because this is what Processing and other languages use.
I have not found this particular variant online, and the only variant that I have found that generates panmagic squares is that with ordinary vector (2, 1) and break vector (1, -1) (http://mathworld.wolfram.com/MagicSquare.html). However, with this method, squares whose orders are multiples of 3 are invalid, meaning that numbers overlap. In the method that I have found and described above, squares whose orders are multiples of 3 are still magic, albeit not panmagic. For the 9x9 square, which has a few properties other than being magic, see Part 2.
The image above was generated with the following Processing program.
magic_square.pde | |
File Size: | 2 kb |
File Type: | pde |