Mosaic matrix: Difference between revisions

Content added Content deleted
mNo edit summary
(→‎{{header|RPL}}: stack-based variant)
Line 1,440: Line 1,440:
1 n '''FOR''' c
1 n '''FOR''' c
r c 2 →LIST r c + 2 MOD NOT PUT '''NEXT NEXT'''
r c 2 →LIST r c + 2 MOD NOT PUT '''NEXT NEXT'''
≫ ≫ <span style="color:blue">'''MOZTX'''</span> STO
≫ ≫ '<span style="color:blue">'''MOZTX'''</span>' STO


4 <span style="color:blue">'''MOZTX'''</span>
4 <span style="color:blue">'''MOZTX'''</span>
Line 1,450: Line 1,450:
[ 0 1 0 1 ]]
[ 0 1 0 1 ]]
</pre>
</pre>
'''Another approach'''
This stack-only one-liner can run only on HP-48G and newer models, due to the presence of the <code>∑LIST</code> instruction:

≪ DUP 2 →LIST DUP 0 CON SWAP SIGN '''DO''' DUP ∑LIST 2 MOD NOT PUTI '''UNTIL''' -64 FS? '''END''' DROP<span style="color:blue">'''MOZTX'''</span> STO
The 1-0-1-.. sequence is created in the stack, then converted into a matrix.
HP-49 RPL version can do it even shorter:
« → n
DUP 'NOT(I+J)MOD 2' LCXM →NUM ≫ ‘<span style="color:blue">'''MOZTX'''</span> STO
« 1 n '''FOR''' j
j 2 MOD
2 n '''START''' 1 OVER - '''NEXT'''
'''NEXT'''
n DUP 2 →LIST →ARRY
» » '<span style="color:blue">'''MOZTX'''</span>' STO
Latest RPL versions can do it even shorter:
≪ DUP 'NOT(I+J) MOD 2' LCXM →NUM'<span style="color:blue">'''MOZTX'''</span>' STO


=={{header|Sidef}}==
=={{header|Sidef}}==