summaryrefslogtreecommitdiff
path: root/simspace/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'simspace/Main.hs')
-rw-r--r--simspace/Main.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/simspace/Main.hs b/simspace/Main.hs
index 07d2705..229bba4 100644
--- a/simspace/Main.hs
+++ b/simspace/Main.hs
@@ -2,7 +2,7 @@ module Main where
import System.Environment
import Control.Monad
-import System.Random (getStdGen, randomRs)
+import System.Random (newStdGen, randomRs)
import Data.List.Split
main :: IO ()
@@ -12,10 +12,17 @@ main = do
[] -> putStrLn "Needs one argument"
(n:_) -> run (read n :: Int)
+-- | Run the cellular automata with a random seed.
run :: Int -> IO ()
run n = do
- g <- getStdGen
+ g <- newStdGen
let init = take n $ randomRs (0,1) g
+ run' init
+
+-- | Version of 'run' that allows for entering your own initial seed.
+run' :: [Int] -> IO ()
+run' init = do
+ let n = length init
let zeros = take n $ repeat 0
let result = takeWhile' (/= zeros) $ chunksOf n $ compute n init
forM_ result $ \r -> putStrLn $ show r