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