Skip to content

Instantly share code, notes, and snippets.

@julienXX
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julienXX/03fa80ee8062d918aafb to your computer and use it in GitHub Desktop.
Save julienXX/03fa80ee8062d918aafb to your computer and use it in GitHub Desktop.
import System.Random
randomCells :: Int -> StdGen -> [Int]
randomCells size gen = take size $ randomRs (0, 1) gen
createGeneration :: [Int] -> Int -> [[Int]] -> [[Int]]
createGeneration [] _ generation = generation -- use _ when you don't use a variable
createGeneration cells width generation =
let line = take width cells
in createGeneration (drop width cells) width (line:generation)
main :: IO() -- declare type signature
main =
let cells = randomCells 12 (mkStdGen 123)
in print (createGeneration cells 4 [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment