Cracked it, I think!
The trick is to keep adding a flipped array to itself, to make more and more values in the result equal until you end up with something manageable, and then work backwards from each of the fairly small number of possible solutions of the "merged" array to obtain all solutions of the original.
Specifically, if we start with a symbolic solution, which I won't try and type as it is rather fiddly, then add to this its vertical flip about the middle row, the result is an array of numbers between 2 and 10 inclusive whose rows, columns, and diagonals sum to 30. And this array is symmetric about the middle row.
Now add to the new array its horizontal flip about the middle column, and you get an array of numbers between 4 and 20 inclusive, whose rows, columns, and diagonals now sum to 60.
Finally, add to _this_ new array its flip about the right diagonal to give an array of numbers between 8 and 40 inclusive, whose rows, columns, and diagonals sum to 120.
Each time one flips and merges, values double in the "pivot" row, column, or diagonal. Bearing that in mind, the resulting array has the following form, in which there are now only the 6 possibly distinct integers a1, a2, a3, b2, b3, c3 :
After dividing out common factors, the equations expressing the sums of each row, column, and diagonal being equal to 120 are:
2 a1 + a2 + a3 = 60
a2 + 2 b2 + b3 = 60
a3 + b3 + 2 c3 = 30
a1 + b2 + 2 c3 = 30
Adding the first two shows that a3 + b3 must be even, say equal 2 t, and then a bit of fiddling around yields the following general solution in the parameters t and a1 :
a2 = 3 (20 - t)
a3 = 3 t - 2 a1
b2 = 2 t - a1
b3 = 2 a1 - t
c3 = 15 - t
where the condition 1 <= c3 <= 5 is equivalent to 10 <= t <= 14, and of course 2 a1, a2, 2 a3, etc (all terms in the above array) must be between 8 and 40 inclusive
Other conditions:
* 8 <= a2 = 3 (20 - t) <= 40 implies (since t is an integer) 3 <= 20 - t <= 13, i.e. 7 <= t <= 17. So the previous bounds are stronger on both sides.
* 4 <= a3 = 3 t - 2 a1 <= 20 implies 3 t - 20 <= 2 a1 <= 3 t - 4
* 4 <= b2 = 2 t - a1 <= 20 implies 2 t - 20 <= a1 <= 2t - 4
* 4 <= b3 = 2 a1 - t <= 20 implies t + 4 <= 2 a1 <= t + 20
Combining the last three gives the following best bounds for a1
I whumped up a simple script to produce all possible triple-merged solutions as above, parametrized by t and a1 subject to the above bounds, and the results are as follows:
Another mega-post below details a simple and quick method to work backwards from these flipped-and-merged arrays, to split them recursively into "solution + flipped solution" and thereby construct every possible original array satisfying the conditions of the problem.
The trick is to keep adding a flipped array to itself, to make more and more values in the result equal until you end up with something manageable, and then work backwards from each of the fairly small number of possible solutions of the "merged" array to obtain all solutions of the original.
Specifically, if we start with a symbolic solution, which I won't try and type as it is rather fiddly, then add to this its vertical flip about the middle row, the result is an array of numbers between 2 and 10 inclusive whose rows, columns, and diagonals sum to 30. And this array is symmetric about the middle row.
Now add to the new array its horizontal flip about the middle column, and you get an array of numbers between 4 and 20 inclusive, whose rows, columns, and diagonals now sum to 60.
Finally, add to _this_ new array its flip about the right diagonal to give an array of numbers between 8 and 40 inclusive, whose rows, columns, and diagonals sum to 120.
Each time one flips and merges, values double in the "pivot" row, column, or diagonal. Bearing that in mind, the resulting array has the following form, in which there are now only the 6 possibly distinct integers a1, a2, a3, b2, b3, c3 :
Code:
(2 a1) a2 (2 a3) a2 (2 a1) a2 (2 b2) (2 b3) (2 b2) a2 (2 a3) (2 b3) (8 c3) (2 b3) (2 a3) a2 (2 b2) (2 b3) (2 b2) a2 (2 a1) a2 (2 a3) a2 (2 a1)
2 a1 + a2 + a3 = 60
a2 + 2 b2 + b3 = 60
a3 + b3 + 2 c3 = 30
a1 + b2 + 2 c3 = 30
Adding the first two shows that a3 + b3 must be even, say equal 2 t, and then a bit of fiddling around yields the following general solution in the parameters t and a1 :
a2 = 3 (20 - t)
a3 = 3 t - 2 a1
b2 = 2 t - a1
b3 = 2 a1 - t
c3 = 15 - t
where the condition 1 <= c3 <= 5 is equivalent to 10 <= t <= 14, and of course 2 a1, a2, 2 a3, etc (all terms in the above array) must be between 8 and 40 inclusive
Other conditions:
* 8 <= a2 = 3 (20 - t) <= 40 implies (since t is an integer) 3 <= 20 - t <= 13, i.e. 7 <= t <= 17. So the previous bounds are stronger on both sides.
* 4 <= a3 = 3 t - 2 a1 <= 20 implies 3 t - 20 <= 2 a1 <= 3 t - 4
* 4 <= b2 = 2 t - a1 <= 20 implies 2 t - 20 <= a1 <= 2t - 4
* 4 <= b3 = 2 a1 - t <= 20 implies t + 4 <= 2 a1 <= t + 20
Combining the last three gives the following best bounds for a1
Code:
t min(a1) max(a1) 10 10 13 11 12 14 12 14 16 13 16 16 14 18 17 <-- impossible
Code:
t a1 a2 a3 b2 b3 c3 10 10 30 10 10 10 5 10 11 30 8 9 12 5 10 12 30 6 8 14 5 10 13 30 4 7 16 5 11 12 27 9 10 13 4 11 13 27 7 9 15 4 11 14 27 5 8 17 4 12 14 24 8 10 16 3 12 15 24 6 9 18 3 12 16 24 4 8 20 3 13 16 21 7 10 19 2



Comment