Mosaic matrix: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a functionally composed version.)
(→‎{{header|Haskell}}: Added a Haskell version)
Line 367: Line 367:
. 1 . 1 . 1 . 1
. 1 . 1 . 1 . 1
</pre>
</pre>

=={{header|Haskell}}==
<lang haskell>import Data.Matrix (Matrix, matrix)

mosaic :: Int -> Matrix Int
mosaic n =
let go (row, col) = succ (col + row) `rem` 2
in matrix n n go

main :: IO ()
main = mapM_ print $ mosaic <$> [7, 8]</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 │
└ ┘
┌ ┐
│ 1 0 1 0 1 0 1 0 │
│ 0 1 0 1 0 1 0 1 │
│ 1 0 1 0 1 0 1 0 │
│ 0 1 0 1 0 1 0 1 │
│ 1 0 1 0 1 0 1 0 │
│ 0 1 0 1 0 1 0 1 │
│ 1 0 1 0 1 0 1 0 │
│ 0 1 0 1 0 1 0 1 │
└ ┘</pre>


=={{header|J}}==
=={{header|J}}==