Created
July 19, 2017 22:30
-
-
Save IronGremlin/d12abe11fb7bcf13565ee3496ef0784c to your computer and use it in GitHub Desktop.
splitTwos
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
flipT :: (x,y) -> (y,x) | |
flipT (x,y) = (y,x) | |
splitOnes :: (Eq a, Ord a) => [a] -> [([a],[a])] | |
splitOnes xs = map flipT . M.toList . M.fromList . map flipT . map (\n -> partition (==n) xs) $ xs | |
splitTwos :: (Eq a, Ord a) => [a] -> [([a],[a])] | |
splitTwos xs = map flipT . M.toList . M.fromList . concatMap splitAgain . splitOnes $ xs | |
where | |
splitAgain (n,xs) = | |
let morePairings = splitOnes xs | |
in map (\(n',rxs) -> (rxs, n++n')) $ morePairings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment