Mosaic matrix: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 11:
=={{header|Ada}}==
<
with Ada.Command_Line;
Line 48:
Put_Line ("Usage: ./mosaic_matrix <side-length>");
end Mosaic_Matrix;</
{{out}}
Line 68:
=={{header|ALGOL 68}}==
<
# 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</
{{out}}
<pre>
Line 116:
=={{header|Arturo}}==
<
loop 1..side 'x ->
print map 1..side 'y [
Line 125:
drawSquare 6
print ""
drawSquare 9</
{{out}}
Line 147:
=={{header|AutoHotkey}}==
<
result .= "Matrix Size: " v "*" v "`n" matrix2txt(mosaicMatrix(v)) "`n"
MsgBox % result
Line 170:
}
return result
}</
{{out}}
<pre>Matrix Size: 8*8
Line 194:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f MOSAIC_MATRIX.AWK
BEGIN {
Line 209:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 229:
=={{header|C}}==
<
void mosaicMatrix(unsigned int n) {
Line 250:
mosaicMatrix(11);
return 0;
}</
{{out}}
Line 279:
=={{header|C++}}==
<
#include <iostream>
Line 309:
}
</syntaxhighlight>
{{out}}
<pre> 1 0 1 0 1 0 1 0
Line 332:
=={{header|F_Sharp|F#}}==
<
// 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>
{{out}}
<pre>
Line 356:
=={{header|FreeBASIC}}==
===Text based===
<
For i As Integer = 1 To n
For j As Integer = 1 To n
Line 366:
mosaicMatrix(9)
Sleep</
{{out}}
<pre>1 . 1 . 1 . 1 . 1
Line 379:
===Graphical===
<
Screenres size, size, 24
Cls
Line 398:
Next x
Bsave "mosaic_matrix.bmp",0
Sleep</
{{out}}
https://www.dropbox.com/s/nbxrttz0j99usos/mosaic_matrix.bmp?dl=0
Line 404:
=={{header|Go}}==
<
import "fmt"
Line 425:
fmt.Println()
mosaicMatrix(8)
}</
{{out}}
Line 448:
=={{header|Haskell}}==
<
mosaic :: Int -> Matrix Int
Line 455:
main :: IO ()
main = mapM_ (print . mosaic) [7, 8]</
{{Out}}
<pre>┌ ┐
Line 480:
Implementation:
<
Examples:
<
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</
=={{header|JavaScript}}==
<
"use strict";
Line 558:
// main
return main();
})();</
{{Out}}
<pre>1 0 1 0 1 0 1
Line 580:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
[range(0;.) | . % 2] as $one
| [range(0;.) | (. + 1) % 2] as $two
| [range(0;.) | if .%2 == 1 then $one else $two end];</
'''Example''':
<
map(join(" ")) | join("\n");
9|mosaicMatrix|display</
{{out}}
<pre>
Line 603:
=={{header|Julia}}==
<
mosaicmat (generic function with 1 method)
Line 635:
0 1 0 1 0
1 0 1 0 1
</syntaxhighlight>
=={{header|Pascal}}==
<
const
Line 670:
begin
printMosaicMatrix(9)
end.</
{{out}}
1⋅1⋅1⋅1⋅1
Line 684:
=={{header|Perl}}==
<
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;</
{{out}}
<pre>1 0 1 0 1
Line 702:
=={{header|Picat}}==
===Imperative===
<
N = 6,
A = new_array(N,N),
Line 711:
end,
println(A[I].to_list.join(" "))
end.</
{{out}}
Line 722:
===List comprehension===
<
N=11,
[[((1+I^J)/\1).to_string:J in 1..N].join:I in 1..N].join("\n").println.</
{{out}}
Line 741:
=={{header|Processing}}==
<
//Aamrun, 27th June 2022
Line 761:
}
}
</syntaxhighlight>
=={{header|Python}}==
===Procedural===
<
for Row in range(size):
for Col in range(size):
Line 772:
else:
print("0", end=" ")
print()</
Output:
<br>
Line 795:
===Functional===
No need for nested conditionals here.
<
Line 845:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>1 0 1 0 1 0 1
Line 866:
=={{header|Quackery}}==
<
[ dip [ temp put [] ]
Line 890:
9 mosaic
witheach
[ witheach [ echo sp ] cr ]</
{{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"
.put for checker 7;
put '';
.put for checker 8;</
{{out}}
<pre>1 0 1 0 1 0 1
Line 940:
=={{header|Red}}==
<
mosaic: function [size][
Line 958:
]
mosaic 8</
{{out}}
Similar to graphical Wren entry
=={{header|Ring}}==
<
# Project : Mosaic matrix
# Date : 2022/18/02
Line 1,026:
next
next
</syntaxhighlight>
Output image:
<br>
Line 1,032:
=={{header|Sidef}}==
<
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 }</
{{out}}
<pre>
Line 1,059:
=={{header|Wren}}==
===Text based===
<
for (i in 0...n) {
for (j in 0...n) {
Line 1,068:
}
mosaicMatrix.call(9)</
{{out}}
Line 1,085:
{{libheader|DOME}}
{{libheader|Go-fonts}}
<
import "graphics" for Canvas, Color, Font, ImageData
Line 1,126:
}
var Game = Main.new(9)</
{{out}}
Line 1,132:
=={{header|XPL0}}==
<
int S, I, J;
[for I:= 0 to S-1 do
Line 1,142:
[DrawMat(6); CrLf(0);
DrawMat(7); CrLf(0);
]</
{{out}}
|