Magic squares of odd order: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
|||
Line 617: | Line 617: | ||
| 66 || 67 || 79 || 91 || 103 || 115 || 6 || 18 || 30 || 42 || 54 |
| 66 || 67 || 79 || 91 || 103 || 115 || 6 || 18 || 30 || 42 || 54 |
||
|} |
|} |
||
=={{header|Arturo}}== |
|||
<lang rebol>oddMagicSquare: function [n][ |
|||
ensure -> and? odd? n |
|||
n >= 0 |
|||
map 1..n 'i [ |
|||
map 1..n 'j [ |
|||
(n * ((i + (j - 1) + n / 2) % n)) + |
|||
(((i - 2) + 2 * j) % n) + 1 |
|||
] |
|||
] |
|||
] |
|||
loop [3 5 7] 'n [ |
|||
print ["Size:" n ", Magic sum:" n*(1+n*n)/2 "\n"] |
|||
loop oddMagicSquare n 'row [ |
|||
loop row 'item [ |
|||
prints pad to :string item 3 |
|||
] |
|||
print "" |
|||
] |
|||
print "" |
|||
]</lang> |
|||
{{out}} |
|||
<pre>Size: 3 , Magic sum: 15 |
|||
8 1 6 |
|||
3 5 7 |
|||
4 9 2 |
|||
Size: 5 , Magic sum: 65 |
|||
17 24 1 8 15 |
|||
23 5 7 14 16 |
|||
4 6 13 20 22 |
|||
10 12 19 21 3 |
|||
11 18 25 2 9 |
|||
Size: 7 , Magic sum: 175 |
|||
30 39 48 1 10 19 28 |
|||
38 47 7 9 18 27 29 |
|||
46 6 8 17 26 35 37 |
|||
5 14 16 25 34 36 45 |
|||
13 15 24 33 42 44 4 |
|||
21 23 32 41 43 3 12 |
|||
22 31 40 49 2 11 20</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |