[Math] Forming a 3×3 magic square with digits 1-9, subject to the constraint that sum of digits in each row, column and diagonal must be equal.

contest-mathlinear algebrarecreational-mathematics

The Problem (Chapter 0, Problem 16 from Fomin's Mathematical Circles):

Form a magic square with the digits 1-9; that is, place them in the boxes of a 3×3 table so that all the sums of the numbers along the rows, columns, and two diagonals are equal.

The sum of numbers from 1-9 is 45, which when partitioned into 3(for each row and column) would be 15. Thus, I felt that the sum of all entries in a row/column/diagonal might be 15(this is certainly not a justified argument, just naive intuition). Continuing upon this, I tried several combinations in a trial-and-error fashion. Despite trying more than two dozen combinations, I've failed to reach a satisfactory answer(one time I was able to prove all the sums to be equal to 15, except a single diagonal).

Next, I tried solving it as a system of linear equations. Considering the magic square to be a $3X3$ matrix(I tried to format a matrix here, but there are some rendering issues so assume a standard matrix), I could devise the following system of equations:
Corresponding to the sum of entries in rows,
$$1) a_{11}+a_{12}+a_{13}=k$$
$$2) a_{21}+a_{22}+a_{23}=k$$
$$3) a_{31}+a_{32}+a_{33}=k$$

Corresponding to the sum of entries in columns,
$$4) a_{11}+a_{21}+a_{31}=k$$
$$5) a_{12}+a_{22}+a_{32}=k$$
$$6) a_{13}+a_{23}+a_{33}=k$$

Finally, corresponding to the sum of entries in diagonals:
$$7) a_{11}+a_{22}+a_{33}=k$$
$$8) a_{13}+a_{22}+a_{31}=k$$

I have 8 equations containing 9 unknown variables(although $k$ has an unknown value, it is still a constant). I'm not sure if these equations alone are sufficient to solve the problem. Beyond this point, I'm clueless about proceeding with either a different approach to solving this problem or continuing with this one. I'd like to know if a solution can be obtained using this approach, and if yes, then how? Any other methods which do not involve a lot of higher mathematics will also be appreciated.

EDIT: I've found one possible solution by trial-and-error method. \begin{matrix} 8 & 1 & 6 \\ 3 & 5 & 7\\ 4 & 9& 2\end{matrix}

Best Answer

The solution you found can be shown to be unique.

The first step is to identify the constant $k$. The three rows (or, alternatively, the three columns) add up to $3k$; together, they comprise all nine digits without repetition, so $3k = 1 + 2 + \cdots + 9 = 45$, so $k = 15$.

The digit $5$ must occur in the middle. Only $5$ can participate in a three-way sum to $15$ in as many as four different ways:

$$ 1+5+9 = 15 \\ 2+5+8 = 15 \\ 3+5+7 = 15 \\ 4+5+6 = 15 $$

Since the center square participates in four such sums, it must contain the digit $5$.

$$ \begin{array}{|c|c|c|} \hline \phantom{8} & \phantom{1} & \phantom{6} \\ \hline \phantom{3} & 5 & \phantom{7} \\ \hline \phantom{4} & \phantom{9} & \phantom{2} \\ \hline \end{array} $$

That means that the other eight digits must occur in pairs on opposite sides of the central $5$: $1$ opposite $9$, $2$ opposite $8$, $3$ opposite $7$, and $4$ opposite $6$.

Of those digits, $1$ and $9$ must occur on opposite sides, because they can each only participate in a three-way sum to $15$ in two different ways, and a corner square would be involved in three such sums. Without loss of generality, put $1$ at the center top, and $9$ at the center bottom.

$$ \begin{array}{|c|c|c|} \hline \phantom{8} & 1 & \phantom{6} \\ \hline \phantom{3} & 5 & \phantom{7} \\ \hline \phantom{4} & 9 & \phantom{2} \\ \hline \end{array} $$

The only other sum that $1$ can be involved in is $1+6+8 = 15$. Again without loss of generality, put $8$ at upper left, and $6$ at upper right. That puts $4$ at lower left, and $2$ at lower right.

$$ \begin{array}{|c|c|c|} \hline 8 & 1 & 6 \\ \hline \phantom{3} & 5 & \phantom{7} \\ \hline 4 & 9 & 2 \\ \hline \end{array} $$

That leaves room only for $3$ at center left, and $7$ at center right.

$$ \begin{array}{|c|c|c|} \hline 8 & 1 & 6 \\ \hline 3 & 5 & 7 \\ \hline 4 & 9 & 2 \\ \hline \end{array} $$

All other $3$-by-$3$ magic squares involving the digits $1$ through $9$ are identical to this one, up to rotation and reflection.


As to whether a solution can be found with your eight equations in nine unknowns: It requires a method more involved than solution of simultaneous equations, because that will not enforce the rule that all nine digits must be used, exactly once each.

Related Question