Spiral matrix: Difference between revisions

Content added Content deleted
(added RPL)
Line 4,918: Line 4,918:


[http://keptarhely.eu/view.php?file=20220218v00xuh6r2.jpeg Spiral matrix]
[http://keptarhely.eu/view.php?file=20220218v00xuh6r2.jpeg Spiral matrix]

=={{header|RPL}}==
{{works with|RPL|HP48-R}}
« { 0 1 } → n step
« { 1 1 } n DUP 2 →LIST -1 CON
0 n SQ 1 - '''FOR''' j
OVER j PUT
DUP2 SWAP step ADD
'''IF IFERR''' GET '''THEN''' DROP2 1 '''ELSE''' -1 ≠ '''END'''
'''THEN''' step EVAL R→C (0,-1) * C→R 2 →LIST 'step' STO '''END'''
SWAP step ADD SWAP
'''NEXT'''
» » '<span style="color:blue">SPIRAL</span>' STO

5 <span style="color:blue">SPIRAL</span>
{{out}}
<pre>
1: [[1 2 3 4 5]
[16 17 18 19 6]
[15 24 25 20 7]
[14 23 22 21 8]
[13 12 11 10 9]]
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==