Rearrange these 9 digits - combinatorics puzzle

4 3 2
7 1 9
6 5 8

Can you rearrange these 9 digits so that in all of the 8 directions the difference between one of the digits and the sum of the remaining two shall always be the same?

In the example all the columns and rows give the difference 3 (thus 4 + 2 - 3, and 1 + 9 - 7, and 6 + 5 - 8, etc.), but the 2 diagonals are wrong, because 8 - (4 + 1) and 6 - (1 + 2) are not allowed.

The sum of two must not be taken from the single digit, but the single-digit from the sum.

How many such solutions exist?

I ran a computer program to find all solutions. Armed with the answer, I've tried to construct an argument for why those are the only solutions, but have not quite managed that.

Firstly, I'll assume without proper proof that:

The $$5$$ is in the centre, and all four lines through the centre have a sum of $$15$$. For this puzzle these lines then can produce a value of $$10-5=5$$.
The four lines therefore use the four pairs $$\{1,9\}$$, $$\{2,8\}$$, $$\{3,7\}$$, and $$\{4,6\}$$. Note that each pair sums to $$10$$, and there are two even pairs of numbers or two odd pairs of numbers.

Now those remaining numbers need to be arranged so that

the outer rows and columns also can produce a value of $$5$$. Note that if $$a+b-c=5$$, then we need exactly one or three of the numbers $$a$$, $$b$$, $$c$$, to be odd. They cannot all be odd, because there are only two odd pairs. Each outer row/column must therefore have exactly one odd number. This means that the even numbers are at the corners, and the odd numbers at the edges.

To reduce by symmetry, we can rotate or reflect the square so that $$2$$ is in the top-left corner (putting $$8$$ in the bottom-right) and $$4$$ is in the top-right corner (putting $$6$$ in the bottom-left).

  2 . 4
. 5 .
6 . 8

Note that if $$a+b-c=5$$, then $$(10-a)+(10-b)-(10-c) = 5$$, so we only need to check that the top row and left column work. The opposite row and column will take care of themselves.
For the top row we can have $$4+2-1$$, $$4+3-2$$, and $$7+2-4$$, but $$9$$ does not work.
For the left column we can have $$6+1-2$$, $$6+2-3$$, $$9+2-6$$, but $$7$$ does not work.

This leaves the following solutions:

 2 1 4
3 5 7
6 9 8

2 3 4  2 3 4
1 5 9  9 5 1
6 7 8  6 7 8

2 7 4  2 7 4
1 5 9  9 5 1
6 3 8  6 3 8

There are $$5$$ solutions, or $$5*8=40$$ if you rotate/reflect them.

I have not found any proof for the assumption I used. My computer program shows that there are no other solutions. Note that if we allow one of the diagonals to have a different number (i.e. only the rows, columns and one diagonal produce matching numbers) then solutions are produced that do not use that assumption, e.g.:

 1 3 5
9 4 8
7 2 6
This square produces $$3$$ on all lines except the "/" diagonal.

• Proof by brute force is still proof. And good job at spotting the one assumption that leads to a logical proof. – user3294068 Sep 13 '19 at 12:58
• yes, all of the solutions are varients with a center number should be 5. this is the right answer and well explained... – Sayed Mohd Ali Sep 13 '19 at 13:00

* The only cases possible. The difference throughout is 5.*

example 1

8 1 4
3 5 7
6 9 2

example 2

2 1 6
3 5 7
4 9 8

example 3

2 1 4
3 5 7
6 9 8