In: Advanced Math
For all n > 2 except n = 6, show how to arrange the numbers 1,2,...,n2 in an n x n array so that each row and column sum to the same constant.
In any magic square, the first number i.e. 1 is stored at
position (n/2, n-1). Let this position be (i,j). The next number is
stored at position (i-1, j+1) where we can consider each row &
column as circular array i.e. they wrap around.
Three conditions hold:
1. The position of next number is calculated by decrementing row number of previous number by 1, and incrementing the column number of previous number by 1. At any time, if the calculated row position becomes -1, it will wrap around to n-1. Similarly, if the calculated column position becomes n, it will wrap around to 0.
2. If the magic square already contains a number at the calculated position, calculated column position will be decremented by 2, and calculated row position will be incremented by 1.
3. If the calculated row position is -1 & calculated column
position is n, the new position would be: (0, n-2).
magic square of size 7 is
20 12 4 45 37 29 28
11 3 44 36 35 27 19
2 43 42 34 26 18 10
49 41 33 25 17 9 1
40 32 24 16 8 7 48
31 23 15 14 6 47 39
22 21 13 5 46 38 30