# Magic Squares

This post is largely inspired by the end of the presentation by Don Steward last weekend.

Magic Squares are puzzles based around a square array of size n, containing the unique positive numbers 1 – n2.

To solve the puzzle, you must place each number into the grid such that the sum of each column, row and diagonal is the same. This total is known as the magic constant.

Let’s consider then, the 3×3 magic square.

First we must find the target total for each row / column / diagonal. This is often given in the puzzle, but it doesn’t have to be. It can be calculated as follows:

So our target in this case is 15.

By observing the above diagram, you can see that the total across all four straight lines must equal 15 x 4 = 60.

We also know that the total of all 9 numbers is 45 (which is…less than 60). Knowing that the central number is used 4 times, we can now deduce what that number is.

If we call it ‘x’, then after considering our total of 45, we have 3x left over, which sums to (60-45)

60 – 45 = 15

x = 5

So our central number must be 5.

Next we’ll prove that 9 must not go in a corner:

If it is placed in a corner, then we soon find we have 3 numbers that *must* go in only two spaces:

Hence 9 does not go in a corner.

Once it is placed between the corner pieces, the rest solves itself:

Squares of this kind are subdivided into two categories: singularly even and doubly even. The former is divisible by 2, but not 4. The latter by both. There are strategies to solve them here.

Magic constants for these are calculated in much the same way as before. Thus the magic constant for a square of size n=4 is:

136 / 4 = 34

We can in fact generalise for the magic constant.

The sum of consecutive numbers can be written as the formula for triangle numbers, which is:

(triangle numbers are just the sum of consecutive numbers starting from 1)

Our ‘n’ for the formula above is in fact going to be ‘n2‘ , because ‘n’ for us refers to the number of squares in a row, therefore ‘n2‘ refers to the number of squares in the entire grid. So we get:

That will give us the sum of numbers, but we need to divide that by n to get the magic constant. Which gives us:

But what about the number of solutions?

In fact there is only one magic square possible for a 3×3 grid. This square is known as the Lo Shu.

No-one as yet has been able to calculate the number of solutions for an n x n grid, but the number of solutions does grow exponentially.

n = 3 (1 solution)

n = 4 (880 solutions)

n = 5 (275305224 solutions)

n = 6 (unknown).

So between magic squares of n=4 and n=5 you pretty much have enough starters to last a lifetime.