Mosaic matrix: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 11:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io; use Ada.Text_Io;
with Ada.Command_Line;
 
Line 48:
Put_Line ("Usage: ./mosaic_matrix <side-length>");
 
end Mosaic_Matrix;</langsyntaxhighlight>
 
{{out}}
Line 68:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # draw a "mosaic matrix" - one with a 1 in the top-left and then #
# alternating with another character vertically and horiontally #
# draws a mosaic matrix with height and width = n using "1" and "." #
Line 88:
print( ( newline ) );
draw mosaic( 11 )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 116:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">drawSquare: function [side][
loop 1..side 'x ->
print map 1..side 'y [
Line 125:
drawSquare 6
print ""
drawSquare 9</langsyntaxhighlight>
 
{{out}}
Line 147:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">for i, v in [8, 9]
result .= "Matrix Size: " v "*" v "`n" matrix2txt(mosaicMatrix(v)) "`n"
MsgBox % result
Line 170:
}
return result
}</langsyntaxhighlight>
{{out}}
<pre>Matrix Size: 8*8
Line 194:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MOSAIC_MATRIX.AWK
BEGIN {
Line 209:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 229:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
void mosaicMatrix(unsigned int n) {
Line 250:
mosaicMatrix(11);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 279:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <concepts>
#include <iostream>
 
Line 309:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre> 1 0 1 0 1 0 1 0
Line 332:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Mosaic matrix. Nigel Galloway: February 18th., 2022
let m11 m=Array2D.init m m (fun n g->if (n+g)%2=0 then 1 else 0)
printfn "%A\n\n%A" (m11 5) (m11 6)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 356:
=={{header|FreeBASIC}}==
===Text based===
<langsyntaxhighlight lang="freebasic">Sub mosaicMatrix(n As Integer)
For i As Integer = 1 To n
For j As Integer = 1 To n
Line 366:
 
mosaicMatrix(9)
Sleep</langsyntaxhighlight>
{{out}}
<pre>1 . 1 . 1 . 1 . 1
Line 379:
 
===Graphical===
<langsyntaxhighlight lang="freebasic">Dim As Integer n = 9, size = 60 * n + 70
Screenres size, size, 24
Cls
Line 398:
Next x
Bsave "mosaic_matrix.bmp",0
Sleep</langsyntaxhighlight>
{{out}}
https://www.dropbox.com/s/nbxrttz0j99usos/mosaic_matrix.bmp?dl=0
Line 404:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 425:
fmt.Println()
mosaicMatrix(8)
}</langsyntaxhighlight>
 
{{out}}
Line 448:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Matrix (Matrix, matrix)
 
mosaic :: Int -> Matrix Int
Line 455:
 
main :: IO ()
main = mapM_ (print . mosaic) [7, 8]</langsyntaxhighlight>
{{Out}}
<pre>┌ ┐
Line 480:
 
Implementation:
<langsyntaxhighlight Jlang="j">mosq=:{{0=2|+/~i.y}}</langsyntaxhighlight>
 
Examples:
 
<langsyntaxhighlight Jlang="j"> mosq 4
1 0 1 0
0 1 0 1
Line 494:
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
"use strict";
 
Line 558:
// main
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>1 0 1 0 1 0 1
Line 580:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang="jq">def mosaicMatrix:
[range(0;.) | . % 2] as $one
| [range(0;.) | (. + 1) % 2] as $two
| [range(0;.) | if .%2 == 1 then $one else $two end];</langsyntaxhighlight>
'''Example''':
<langsyntaxhighlight lang="jq">def display:
map(join(" ")) | join("\n");
 
9|mosaicMatrix|display</langsyntaxhighlight>
{{out}}
<pre>
Line 603:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">julia> mosaicmat(n) = (m = n + iseven(n); reshape([Int(isodd(i)) for i in 1:m^2], m, m)[1:n, 1:n])
mosaicmat (generic function with 1 method)
 
Line 635:
0 1 0 1 0
1 0 1 0 1
</syntaxhighlight>
</lang>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">program mosaicMatrix(output);
 
const
Line 670:
begin
printMosaicMatrix(9)
end.</langsyntaxhighlight>
{{out}}
1⋅1⋅1⋅1⋅1
Line 684:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
 
my $n = 5;
say join ' ', @$_ for map { $_%2 ? [map { $_%2 ? 1 : 0 } 1..$n] : [map { $_%2 ? 0 : 1 } 1..$n] } 1..$n;</langsyntaxhighlight>
{{out}}
<pre>1 0 1 0 1
Line 702:
=={{header|Picat}}==
===Imperative===
<langsyntaxhighlight Picatlang="picat">go =>
N = 6,
A = new_array(N,N),
Line 711:
end,
println(A[I].to_list.join(" "))
end.</langsyntaxhighlight>
 
{{out}}
Line 722:
 
===List comprehension===
<langsyntaxhighlight Picatlang="picat">main =>
N=11,
[[((1+I^J)/\1).to_string:J in 1..N].join:I in 1..N].join("\n").println.</langsyntaxhighlight>
 
{{out}}
Line 741:
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">
//Aamrun, 27th June 2022
 
Line 761:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
===Procedural===
<langsyntaxhighlight lang="python">size = 9
for Row in range(size):
for Col in range(size):
Line 772:
else:
print("0", end=" ")
print()</langsyntaxhighlight>
Output:
<br>
Line 795:
===Functional===
No need for nested conditionals here.
<langsyntaxhighlight lang="python">'''Mosaic grid'''
 
 
Line 845:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>1 0 1 0 1 0 1
Line 866:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ 1 & not ] is even ( n --> b )
 
[ dip [ temp put [] ]
Line 890:
9 mosaic
witheach
[ witheach [ echo sp ] cr ]</langsyntaxhighlight>
 
{{out}}
Line 916:
=={{header|Raku}}==
This isn't a matrix, especially if it is supposed to be graphical; it's a very small (or extremely low resolution) bitmap.
<syntaxhighlight lang="raku" perl6line>sub checker ($n) { (^$n).map: { 1 xx $n Z× (flat ($_ %% 2, $_ % 2) xx *) } }
 
.put for checker 7;
put '';
.put for checker 8;</langsyntaxhighlight>
{{out}}
<pre>1 0 1 0 1 0 1
Line 940:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red[]
 
mosaic: function [size][
Line 958:
]
 
mosaic 8</langsyntaxhighlight>
{{out}}
Similar to graphical Wren entry
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Mosaic matrix
# Date : 2022/18/02
Line 1,026:
next
next
</syntaxhighlight>
</lang>
Output image:
<br>
Line 1,032:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func mosaic_matrix(n) {
n.of {|k|
var(a,b) = (k.is_even ? (1,0) : (0,1))
Line 1,040:
 
mosaic_matrix(5).each { .join(' ').say }; say ''
mosaic_matrix(6).each { .join(' ').say }</langsyntaxhighlight>
{{out}}
<pre>
Line 1,059:
=={{header|Wren}}==
===Text based===
<langsyntaxhighlight lang="ecmascript">var mosaicMatrix = Fn.new { |n|
for (i in 0...n) {
for (j in 0...n) {
Line 1,068:
}
 
mosaicMatrix.call(9)</langsyntaxhighlight>
 
{{out}}
Line 1,085:
{{libheader|DOME}}
{{libheader|Go-fonts}}
<langsyntaxhighlight lang="ecmascript">import "dome" for Window
import "graphics" for Canvas, Color, Font, ImageData
 
Line 1,126:
}
 
var Game = Main.new(9)</langsyntaxhighlight>
 
{{out}}
Line 1,132:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">proc DrawMat(S);
int S, I, J;
[for I:= 0 to S-1 do
Line 1,142:
[DrawMat(6); CrLf(0);
DrawMat(7); CrLf(0);
]</langsyntaxhighlight>
 
{{out}}
10,327

edits