How many combination has a magic square

1.2k Views Asked by At

Let's assume that I have magic square 3x3 and I know middle number. How many combinations can I create if I try to solve that? Is there a way how to find them all?

1

There are 1 best solutions below

0
On

If you have a magic square of sum $N$:

$$\begin{array}{|c|c|c|} \hline a & b & c \\ \hline d & e & f \\ \hline g & h & i \\ \hline \end{array}$$

then if you add or substract the same number from all the cells, you also get a magic square, particularly:

$$\begin{array}{|c|c|c|} \hline a-e & b-e & c-e \\ \hline d-e & 0 & f-e \\ \hline g-e & h-e & i-e \\ \hline \end{array}$$

is a magic square of sum $N-3e$.

So WLOG we can assume that the central number is $0$. Then

$$\begin{array}{|c|c|c|} \hline -a & b & -a+c \\ \hline c & 0 & -c \\ \hline -a+b & -b & a \\ \hline \end{array}$$

is a square number of sum $0$ as long as $2a = b + c$ and $b$ and $c$ are different nonzero integers of the same parity. If you choose $b > c > 0$ with you automatically remove most of the rotations and reflexions.

Particularly, you have this infinite set of solutions:

$$\begin{array}{|c|c|c|} \hline 1-b & b & -1 \\ \hline b-2 & 0 & 2-b \\ \hline 1 & -b & b-1 \\ \hline \end{array}$$

For any $b > 3$. If you want to exclude $0$, just add $n$ to every cell, where $n\not\in \{b,b-1,b-2\}$. Add $n > b-2$ to every cell to only have positive values in the cells.