#### Agnishom wrote:

Is there a way to figure out the magic number without sorting a square?

If there are n rows, the magic number must be

sum{all numbers}/n

The method I use is partly trial and improvement.

(i) Add up all the numbers. Divide by n to get the required total (=T) for any row.

(ii) Pick any set of n numbers that add to T. Make that row one.

(iii) Pick any set from the remainder that add to make T. Make that row two.

(iv) Continue like this until you have all the rows or an impossible set left.

(v) If the latter juggle some numbers about until the rows all work.

(vi) Now shuffle the numbers only within their rows until a column works too.

(vii) Keep that column fixed but shuffle the remainder within their rows until all the columns work.

(viii) Swap whole rows or whole columns until the diagonals work too.

example with 1,2,3,4,5,6,7,8,9

(i) sum = 45 => T = 45/3 = 15

(ii) I chose 9, 1, 5

(iii) Then I chose 7, 2 6 which meant the third row was bound to work as well: (iv)+ (v) 3,4,8 diagram one.

(vi) + (vii) see diagram two

(viii) The last two diagrams show whole row and column swaps.

Bob