One-dimensional cellular automata: Difference between revisions

m
→‎{{header|Haskell}}: Applied Ormolu, preferred putStrLn to print, updated output.
m (→‎{{header|Haskell}}: Applied Ormolu, preferred putStrLn to print, updated output.)
Line 2,524:
 
=={{header|Haskell}}==
<lang haskell>import SystemData.RandomList (newStdGen, randomRsunfoldr)
import DataSystem.ListRandom (unfoldrnewStdGen, randomRs)
 
bnd :: String -> Char
Line 2,531:
bnd "#_#" = '#'
bnd "##_" = '#'
bnd _ = '_'
 
nxt :: String -> String
Line 2,541:
lahmahgaan :: String -> [String]
lahmahgaan xs =
init
init . until ((==) . last <*> (last . init)) ((<>) <*> (return . nxt . last)) $
[xs, nxt xs]. until
((==) . last <*> (last . init))
init . until ((==) . last <*> (last . init)) ((<>) <*> (return . nxt . last)) $
$ [xs, nxt xs]
 
main :: IO ()
Line 2,548 ⟶ 2,551:
g <- newStdGen
let oersoep = map ("_#" !!) . take 36 $ randomRs (0, 1) g
mapM_ printputStrLn . lahmahgaan $ oersoep</lang>
{{Out}}
For example:
<lang haskell>*Life1D> mapM_ print . lahmahgaan $ "_###_##_#_#_#_#__#__"
"<pre>_##_#_#__#_#_#_#_#__##_#######_#_#__"##
"_#_##_#____#_#_#_##_#______"##_____##_#___##
_#_##______#_#_#####_#_____###____##
"__##___##_#_#_______"
"__###_______#_##___##______#_#________"____##
"__#_#________###___#_#_______#_____##_________"
___#_________#_#___##_____________##
"__##____###_________"
______________#____##_____________##
"__##____#_#_________"
___________________##_____________##</pre>
"__##_____#__________"
"__##________________"
*Life1D> main
"__##_##__#____###__#__#_______#_#_##"
"__#####_______#_#______________#_###"
"__#___#________#________________##_#"
"________________________________###_"
"________________________________#_#_"
"_________________________________#__"
"____________________________________"</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
9,655

edits