One-dimensional cellular automata: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Applied Ormolu, preferred putStrLn to print, updated output.) |
|||
Line 2,524: | Line 2,524: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import |
<lang haskell>import Data.List (unfoldr) |
||
import |
import System.Random (newStdGen, randomRs) |
||
bnd :: String -> Char |
bnd :: String -> Char |
||
Line 2,531: | Line 2,531: | ||
bnd "#_#" = '#' |
bnd "#_#" = '#' |
||
bnd "##_" = '#' |
bnd "##_" = '#' |
||
bnd |
bnd _ = '_' |
||
nxt :: String -> String |
nxt :: String -> String |
||
Line 2,541: | Line 2,541: | ||
lahmahgaan :: String -> [String] |
lahmahgaan :: String -> [String] |
||
lahmahgaan xs = |
lahmahgaan xs = |
||
init |
|||
⚫ | |||
. until |
|||
((==) . last <*> (last . init)) |
|||
⚫ | |||
$ [xs, nxt xs] |
|||
main :: IO () |
main :: IO () |
||
Line 2,548: | Line 2,551: | ||
g <- newStdGen |
g <- newStdGen |
||
let oersoep = map ("_#" !!) . take 36 $ randomRs (0, 1) g |
let oersoep = map ("_#" !!) . take 36 $ randomRs (0, 1) g |
||
mapM_ |
mapM_ putStrLn . lahmahgaan $ oersoep</lang> |
||
{{Out}} |
{{Out}} |
||
For example: |
|||
<lang haskell>*Life1D> mapM_ print . lahmahgaan $ "_###_##_#_#_#_#__#__" |
|||
<pre>_##_#_#__#_#_#_#_###_#######_#_#__## |
|||
_###_#____#_#_#_##_###_____##_#___## |
|||
_#_##______#_#_#####_#_____###____## |
|||
"__##___##_#_#_______" |
|||
__###_______#_##___##______#_#____## |
|||
__#_#________###___##_______#_____## |
|||
___#_________#_#___##_____________## |
|||
"__##____###_________" |
|||
______________#____##_____________## |
|||
"__##____#_#_________" |
|||
___________________##_____________##</pre> |
|||
"__##_____#__________" |
|||
"__##________________" |
|||
*Life1D> main |
|||
"__##_##__#____###__#__#_______#_#_##" |
|||
"__#####_______#_#______________#_###" |
|||
"__#___#________#________________##_#" |
|||
"________________________________###_" |
|||
"________________________________#_#_" |
|||
"_________________________________#__" |
|||
"____________________________________"</lang> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |