Magic squares of odd order: Difference between revisions

m
No edit summary
Line 2,831:
See [[Magic_squares/Lua]].
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Rotate rows and columns of the initial matrix with rows filled in order 1 2 3 .... N^2
 
Method from http://www.jsoftware.com/papers/eem/magicsq.htm
<lang Mathematica>rp[v_, pos_] := RotateRight[v, (Length[v] + 1)/2 - pos];
 
<lang Mathematica>
rp[v_, pos_] := RotateRight[v, (Length[v] + 1)/2 - pos];
rho[m_] := MapIndexed[rp, m];
magic[n_] :=
Line 2,843 ⟶ 2,840:
 
square = magic[11] // Grid
Print["Magic number is ", Total[square[[1, 1]]]]</lang>
{{out}}
</lang>
{{out}} (alignment lost in translation to text):
<pre>{68, 80, 92, 104, 116, 7, 19, 31, 43, 55, 56},
 
{68, 80, 92, 104, 116, 7, 19, 31, 43, 55, 56},
{81, 93, 105, 117, 8, 20, 32, 44, 45, 57, 69},
{94, 106, 118, 9, 21, 33, 34, 46, 58, 70, 82},
Line 2,858 ⟶ 2,854:
{53, 65, 77, 78, 90, 102, 114, 5, 17, 29, 41},
{66, 67, 79, 91, 103, 115, 6, 18, 30, 42, 54}
 
Magic number is 671
</langpre>
 
Output from code that checks the results
Rows
1,111

edits