Skip to content

Instantly share code, notes, and snippets.

@IronGremlin
Created July 19, 2017 22:30
Show Gist options
  • Save IronGremlin/d12abe11fb7bcf13565ee3496ef0784c to your computer and use it in GitHub Desktop.
Save IronGremlin/d12abe11fb7bcf13565ee3496ef0784c to your computer and use it in GitHub Desktop.
splitTwos
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