Jump to content

One-dimensional cellular automata: Difference between revisions

(add FreeBASIC)
(→‎{{header|Haskell}}: Minor tidying)
Line 2,373:
 
bnd :: String -> Char
bnd bs"_##" = '#'
bnd "#_#_" ->= '#'
case bs of
bnd "_##_" ->= '#'
bnd "#_#" ->= '#_'
"##_" -> '#'
_ -> '_'
 
donxtnxt :: String -> String
nxt = unfoldr go . ('_' :) . (<> "_")
donxt xs =
unfoldrwhere
go [_, _] ->= Nothing
(\xs ->
go xs = Just case(bnd $ take 3 xs, ofdrop 1 xs)
[_, _] -> Nothing
_ -> Just (bnd $ take 3 xs, drop 1 xs)) $
'_' : xs ++ "_"
 
lahmahgaan :: String -> [String]
lahmahgaan xs =
init . until ((==) . last <*> (last . init)) ((++<>) <*> (return . donxtnxt . last)) $
init .
[xs, donxtnxt xs]
until ((==) . last <*> (last . init)) ((++) <*> (return . donxt . last)) $
[xs, donxt xs]
 
main :: IO ()
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.