One-dimensional cellular automata: Difference between revisions

Content added Content deleted
(add FreeBASIC)
(→‎{{header|Haskell}}: Minor tidying)
Line 2,373: Line 2,373:


bnd :: String -> Char
bnd :: String -> Char
bnd bs =
bnd "_##" = '#'
bnd "#_#" = '#'
case bs of
"_##" -> '#'
bnd "##_" = '#'
"#_#" -> '#'
bnd _ = '_'
"##_" -> '#'
_ -> '_'


donxt :: String -> String
nxt :: String -> String
nxt = unfoldr go . ('_' :) . (<> "_")
donxt xs =
unfoldr
where
go [_, _] = Nothing
(\xs ->
case xs of
go xs = Just (bnd $ take 3 xs, drop 1 xs)
[_, _] -> Nothing
_ -> Just (bnd $ take 3 xs, drop 1 xs)) $
'_' : xs ++ "_"


lahmahgaan :: String -> [String]
lahmahgaan :: String -> [String]
lahmahgaan xs =
lahmahgaan xs =
init . until ((==) . last <*> (last . init)) ((<>) <*> (return . nxt . last)) $
init .
[xs, nxt xs]
until ((==) . last <*> (last . init)) ((++) <*> (return . donxt . last)) $
[xs, donxt xs]


main :: IO ()
main :: IO ()