Spiral matrix: Difference between revisions

Added Arturo implementation
(→‎JS ES6: Generalized output formatting for larger spirals.)
(Added Arturo implementation)
Line 835:
| 12 || 11 || 10 || 9 || 8
|}
 
=={{header|Arturo}}==
{{trans|Python}}
<lang rebol>spiralMatrix: function [n][
m: new array.of: @[n,n] null
 
[dx, dy, x, y]: [1, 0, 0, 0]
 
loop 0..dec n^2 'i [
m\[y]\[x]: i
 
[nx,ny]: @[x+dx, y+dy]
 
if? and? [and? [in? nx 0..n-1][in? ny 0..n-1]][
null? m\[ny]\[nx]
][
[x,y]: @[nx, ny]
]
else [
bdx: dx
[dx, dy]: @[neg dy, bdx]
[x, y]: @[x+dx, y+dy]
]
]
 
return m
]
 
loop spiralMatrix 5 'row [
print map row 'x -> pad to :string x 4
]</lang>
 
{{out}}
 
<pre> 0 1 2 3 4
15 16 17 18 5
14 23 24 19 6
13 22 21 20 7
12 11 10 9 8</pre>
 
=={{header|AutoHotkey}}==
1,532

edits