The numbers in each row, column, and diagonal all sum up to 15 (ex. 2+7+6=15). It is called a magic square. There are infinitely many of them with different sizes, and there are also different types. Here are a few of them.
1. Normal magic square - rows, columns and diagonals add up to the same number, or magic constant
2. Semimagic square - rows and columns add up to the same magic constant
3. Antimagic square - Made of consecutive integers, rows and columns add up to different numbers
However, the one we are interested in is called a panmagic square. In a panmagic square, the rows, columns, and pandiagonals add up to the same magic constant, but what is a pandiagonal?
A pandiagonal is a diagonal that "wraps around" the square. In the image below, the white squares in the grid lie on one of the pandiagonals.
1. Normal magic square - rows, columns and diagonals add up to the same number, or magic constant
2. Semimagic square - rows and columns add up to the same magic constant
3. Antimagic square - Made of consecutive integers, rows and columns add up to different numbers
However, the one we are interested in is called a panmagic square. In a panmagic square, the rows, columns, and pandiagonals add up to the same magic constant, but what is a pandiagonal?
A pandiagonal is a diagonal that "wraps around" the square. In the image below, the white squares in the grid lie on one of the pandiagonals.
Panmagic squares are considerably more difficult to make than magic or semimagic ones, but there is an easy way to do it. However, there are a few catches. If the side of the board, or n, is even, multiple numbers will end up at the same place, and a magic square will not be created. If n is divisible by 3, the resulting square is only semimagic, but it can be made magic if the average of all of the numbers in the square is moved to the center.
Update: I have found a slightly easier way to generate panmagic squares than the one described below. It is detailed in Part 3.
Here is the method (with the 5x5 square as an example, or n = 5):
1. Put the number 1 in the top-left corner. (New squares are highlighted yellow.)
Update: I have found a slightly easier way to generate panmagic squares than the one described below. It is detailed in Part 3.
Here is the method (with the 5x5 square as an example, or n = 5):
1. Put the number 1 in the top-left corner. (New squares are highlighted yellow.)
2. Go down 1 square and right 2 squares, adding 1 as you go. If you go out of one side of the square, wrap around to the other. Do this until there is overlap. When there is overlap, do not overwrite the number that is already there. Your magic square should now look like this:
3. Start at the square with 1, and go down 1 square and left 2 squares, adding n each time, until there is overlap. Again, wrap around the square if you go out of one side.
4. Repeat Step 3, starting with the square with 2. This time, you will have to wrap from not only left to right, but also bottom to top.
5. Keep repeating Step 3, increasing the number of the starting square by 1 each time (start with 3, then 4, etc) until the magic square is filled.
The final product: