Created
April 21, 2020 16:31
-
-
Save scravy/38d3f509bf5409b4bba0a90282a1a1f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Haskell2010, LambdaCase #-} | |
import Data.List (nub) | |
data Symbol = M | I | U deriving (Eq, Show) | |
apply = \case | |
M : xs -> [ M : xs ++ xs ] | |
I : I : I : xs -> [ U : xs ] | |
U : U : xs -> [ xs ] | |
I : [] -> [ I : U : [] ] | |
xs -> [] | |
applyAll = \case | |
[] -> [] | |
ss@(s : rs) -> apply ss ++ map (s :) (applyAll rs) | |
nextGen (curGen, start) = (oldGen, noDupes (start >>= applyAll)) | |
where | |
noDupes = nub . filter (not . flip elem oldGen) | |
oldGen = start ++ curGen | |
enumerateAll start = concatMap snd (iterate nextGen ([], [start])) | |
main = mapM_ (putStrLn . map (head . show)) (enumerateAll [M, I]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment