Mosaic matrix: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
mNo edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
(4 intermediate revisions by 2 users not shown)
Line 925:
1 0 1 0 1
</syntaxhighlight>
 
=={{header|K}}==
K6
<syntaxhighlight lang="k">mosaic: {x=/:x}2!!:
 
mosaic 6</syntaxhighlight>
{{out}}
<pre>(1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1)</pre>
 
=={{header|Maxima}}==
Line 1,435 ⟶ 1,448:
 
=={{header|RPL}}==
'''Filling a matrix'''
≪ → n
≪ n DUP 2 →LIST 0 CON
1 n '''FOR''' r
1 n '''FOR''' c
r c 2 →LIST r c + 2 MOD NOT PUT '''NEXT NEXT'''
'''NEXT NEXT'''
≫ ≫ '<span style="color:blue">'''MOZTX'''</span>' STO
 
4 <span style="color:blue">'''MOZTX'''</span>
Line 1,450 ⟶ 1,465:
[ 0 1 0 1 ]]
</pre>
'''Filling the stack'''
This stack-only one-liner can run only on HP-48G and newer models, due to the presence of the <code>∑LIST</code> instruction:
« → n
≪ 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
« 1 n '''FOR''' j
HP-49 RPL version can do it even shorter:
j 2 MOD
≪ DUP 'NOT(I+J)MOD 2' LCXM →NUM ≫ ‘<span style="color:blue">'''MOZTX'''</span>’ STO
2 n '''START''' DUP NOT '''NEXT'''
'''NEXT'''
n DUP 2 →LIST →ARRY
» DUP» 'NOT(I+J)MOD 2' LCXM →NUM ≫ ‘<span style="color:blue">'''MOZTX'''</span>' STO
'''Direct approach'''
 
Latest RPL versions have a specific instruction to generate a matrix ruled by a formula.
≪ DUP 2 →LIST DUP 0 CON SWAP SIGN '''DO'''NOT(I+J) DUP ∑LISTMOD 2 MOD NOT PUTI '''UNTIL''' -64LCXM FS? '''END''' DROP→NUM'<span style="color:blue">'''MOZTX'''</span>' STO
 
=={{header|Sidef}}==
Line 1,483 ⟶ 1,506:
=={{header|Wren}}==
===Text based===
<syntaxhighlight lang="ecmascriptwren">var mosaicMatrix = Fn.new { |n|
for (i in 0...n) {
for (j in 0...n) {
Line 1,509 ⟶ 1,532:
{{libheader|DOME}}
{{libheader|Go-fonts}}
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color, Font, ImageData
 
9,482

edits