Skip to content

Instantly share code, notes, and snippets.

@GallagherCommaJack
Last active August 29, 2015 13:56
Show Gist options
  • Save GallagherCommaJack/9125933 to your computer and use it in GitHub Desktop.
Save GallagherCommaJack/9125933 to your computer and use it in GitHub Desktop.
data MIU = M | I | U deriving (Show, Read, Eq)
type STR = [MIU]
rep2 = concat . (replicate 2)
start = [M,I]
r1 :: STR -> STR
r1 ms = ms ++ [U]
r2 :: STR -> STR
r2 (M:ms) = M:rep2 ms
r2 ms = ms
r3 :: Int -> STR -> STR
r3 0 (I:I:I:ms) = U:ms
r3 n (I:ms@(I:I:qs)) = I:r3 (n - 1) ms
r3 n (m:ms) = m : r3 n ms
r3 _ [] = []
r4 :: Int -> STR -> STR
r4 0 (U:U:ms) = ms
r4 n (U:ms@(U:m)) = U:r4 (n - 1) ms
r4 n (m:ms) = m:r4 n ms
r4 _ [] = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment