Skip to content

Instantly share code, notes, and snippets.

@recurse
Created May 19, 2016 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recurse/fa5255558e5dcffd82525271538bd92c to your computer and use it in GitHub Desktop.
Save recurse/fa5255558e5dcffd82525271538bd92c to your computer and use it in GitHub Desktop.
next :: [Int] -> [Int]
next [] = []
next (i1:is) = case is of
[] -> [0]
i2:_ -> i2:(next' i1 is) where
next' l [] = [l]
next' l (i:is) = case is of
[] -> [i]
r:_ -> (l `xor` r):(next' i is) where
xor 0 0 = 0
xor 1 0 = 1
xor 0 1 = 1
xor 1 1 = 0
doCA :: Int -> [Int] -> [[Int]]
doCA n s = take n $ scanl doNext s [0..] where
doNext l _ = next l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment