(consecutively concentric squares)
The bones 4(n-1) border numbers form 2(n-1) ± pairs. The + numbers are in the range:
((n-2)²+1)/2 to (n²-1)/2
The sum of each bones row, column, and main diagonal is 0.
Therefore, the border constraints are:
The square is divided into the following regions:
Define rrel = row - (n+1)/2, crel = column - (n+1)/2.
Then, the basic formula used here to compute a cell number is 2x² + 2y + c,
where, for each region:
The algorithm is:
Summary:
region x y c sign -------- ----------- ----------- ------- ---------- center rrel crel 0 0 NW rrel 0 1 + SE rrel 0 1 - NNW rrel crel -1 + SSW rrel crel -1 - N rrel crel 2 - S rrel crel 2 + NNE rrel crel 1 - SSE rrel crel 1 + NE rrel 0 -1 + SW rrel 0 -1 - ENE crel rrel 0 + WNW crel rrel 0 - E crel rrel 0 + W crel rrel 0 - ESE crel rrel 2 - WSW crel rrel 2 +
Is the algorithm correct for all odd order squares?
It is sufficient to check the border, since the test applies recursively through the nested squares down to order 3.
Let B be the bones, m = (n+1)/2, and X = 2(1-m)² = 2(n-m)².
In row 1, rrel = 1-m, crel ranges from 1-m to n-m.
B(1,1) = X + 1 B(1,m) = -(X + 2) B(1,n) = X - 1 The sum of these is X + 1 - X - 2 + X - 1 = X - 2. NNW numbers are X + 2crel - 1. NNE numbers are -(X + 2crel + 1). Summing NNW,NNE number pairs from left to right, we have: B(1,2) + B(1,m+1) = X + 2(2-m) - 1 - X - 2(1) - 1 = -(n+1) … B(1,m-1) + B(1,n-1) = X + 2(-1) - 1 - X - 2(n-1-m) - 1 = -(n+1) The sum of these (n-3)/2 pairs is -(n+1)(n-3)/2 = -(X - 2).
Row 1 total is (X - 2) - (X - 2) = 0.
Rows 2 to n-1 have ± the same numbers at each end.
Row n contains ± the same numbers as row 1.
In column 1, rrel ranges from 1-m to n-m, crel = 1-m.
B(1,1) = X + 1 B(m,1) = -X B(n,1) = -(X - 1) The sum of these is X + 1 - X - X + 1 = -(X - 2). WNW numbers are -(X + 2rrel). WSW numbers are X + 2rrel + 2. Summing the WNW,WSW number pairs from top to bottom, we have: B(2,1) + B(m+1,1) = -X - 2(2-m) + X + 2(1) + 2 = n+1 … B(m-1,1) + B(n-1,1) = -X - 2(-1) + X + 2(n - 1 - m) + 2 = n+1 The sum of these (n-3)/2 pairs is (n+1)(n-3)/2 = X - 2.
Column 1 total is -(X - 2) + (X - 2) = 0.
Columns 2 to n-1 have ± the same numbers at each end.
Column n contains ± the same numbers as column 1.
Are the border numbers correct, that is, in the right range with no duplicates?
There are 4(n-1) border numbers or 2(n-1) ± pairs.
There is 1 pair in each of the main diagonals,
1 in the center row, and 1 in the center column.
The remaining 2(n-1) - 4 pairs are in the (NNW,SSW), (NNE,SSE), (WNW,ENE),
and (WSW,ESE) sectors.
The placing of the 2(n-1) positive numbers is:
----- n-3 numbers alternating NNW, ENE NNW: B(1,2) = X + 2(2-m) - 1 = X - n + 2 ENE: B(2,n) = X + 2(2-m) = X - n + 3 … NNW: B(1,m-1) = X + 2(-1) - 1 = X - 3 ENE: B(m-1,n) = X + 2(-1) = X - 2 NE: B(1,n) = X - 1 E: B(m,n) = X NW: B(1,1) = X + 1 S: B(n,m) = X + 2 ----- n-3 numbers alternating SSE, WSW SSE: B(n,m+1) = X + 2(1) + 1 = X + 3 WSW: B(m+1,1) = X + 2(1) + 2 = X + 4 … SSE: B(n,n-1) = X + 2(n-1-m) + 1 = X + n - 2 WSW: B(n-1,1) = X + 2(n-1-m) + 2 = X + n - 1
The next smaller odd order square is order k = n-2.
Its biggest border number is 2(1-(k+1)/2)² + k - 1 = X - n + 1.
The smallest border number of the order n is X - n + 2.
That is, the smallest border number of the order n is 1 greater
than the biggest border number of the order n-2.