Add new function to print a grid
This commit is contained in:
parent
248e364f39
commit
5bae8c5796
9
life.hs
9
life.hs
@ -3,6 +3,13 @@ import Matrix
|
|||||||
type Cell = Int
|
type Cell = Int
|
||||||
type Grid = Mat Cell
|
type Grid = Mat Cell
|
||||||
|
|
||||||
|
-- | Print a grid
|
||||||
|
gprint :: Grid -> IO ()
|
||||||
|
gprint = putStrLn . map replace . show
|
||||||
|
where
|
||||||
|
replace '1' = '■'
|
||||||
|
replace '0' = '.'
|
||||||
|
replace a = a
|
||||||
|
|
||||||
-- | Get the state of a cell
|
-- | Get the state of a cell
|
||||||
-- 0 when out of the grid
|
-- 0 when out of the grid
|
||||||
@ -31,7 +38,7 @@ next :: Grid -> Grid
|
|||||||
next g = fmap (alive g) (indeces g)
|
next g = fmap (alive g) (indeces g)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = mapM_ print (iterate next grid)
|
main = mapM_ gprint (iterate next grid)
|
||||||
|
|
||||||
grid = Mat [
|
grid = Mat [
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
Loading…
Reference in New Issue
Block a user