Mosaic matrix: Difference between revisions

Content added Content deleted
(added AWK)
Line 384: Line 384:
0 1 0 1 0
0 1 0 1 0
1 0 1 0 1</lang>
1 0 1 0 1</lang>

=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>def mosaicMatrix:
. as $n
| [range(0;$n) | . % 2] as $one
| [range(0;$n) | (. + 1) % 2] as $two
| reduce range(0;$n) as $i ([];
. + [if $i%2 == 1 then $one else $two end]);</lang>
'''Example''':
<lang jq>def display:
map(join(" ")) | join("\n");

9|mosaicMatrix|display</lang>
{{out}}
<pre>
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
</pre>


=={{header|Julia}}==
=={{header|Julia}}==