Restyle
This commit is contained in:
parent
57120a5dae
commit
c4c90e021e
14
life.hs
14
life.hs
@ -1,5 +1,6 @@
|
|||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.List
|
import Data.List ((\\))
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
import Matrix
|
import Matrix
|
||||||
|
|
||||||
type Cell = Int
|
type Cell = Int
|
||||||
@ -16,9 +17,7 @@ gprint = putStrLn . map replace . show
|
|||||||
-- | Get the state of a cell
|
-- | Get the state of a cell
|
||||||
-- 0 when out of the grid
|
-- 0 when out of the grid
|
||||||
(!) :: Grid -> Pos -> Cell
|
(!) :: Grid -> Pos -> Cell
|
||||||
(Mat g) ! (x, y) = case g ?? y >>= (?? x) of
|
(Mat g) ! (x, y) = fromMaybe 0 (g ?? y >>= (?? x))
|
||||||
Nothing -> 0
|
|
||||||
Just v -> v
|
|
||||||
|
|
||||||
-- | List of neighbours cells
|
-- | List of neighbours cells
|
||||||
near :: Grid -> Pos -> [Cell]
|
near :: Grid -> Pos -> [Cell]
|
||||||
@ -42,12 +41,11 @@ next g = alive g <$> indeces g
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = mapM_ gprint (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]
|
||||||
, [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
, [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
, [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
, [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
, [0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
, [0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
, [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