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