Skip to content

Instantly share code, notes, and snippets.

@mizunashi-mana
Created December 4, 2019 16:05
Show Gist options
  • Save mizunashi-mana/34c6f7363fda7e9fe79688aee11dea4f to your computer and use it in GitHub Desktop.
Save mizunashi-mana/34c6f7363fda7e9fe79688aee11dea4f to your computer and use it in GitHub Desktop.
module BitSeq where
merge :: Int -> [a] -> [a] -> [a]
merge n xs ys = goXs n xs
where
goXs 0 zs = goYs n ys zs
goXs m (z:zs) = z:goXs (m - 1) zs
goXs _ [] = error "unreachable"
goYs 0 zs r = merge (n + 1) r zs
goYs m (z:zs) r = z:goYs (m - 1) zs r
goYs _ [] _ = error "unreachable"
-- |
--
-- >>> take 10 ns
-- [[],[0],[1],[0,0],[0,1],[1,0],[1,1],[0,0,0],[0,0,1],[0,1,0]]
--
ns :: [[Int]]
ns = let l = []:merge 1 [0:xs | xs <- l] [1:xs | xs <- l] in l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment