Skip to content

Instantly share code, notes, and snippets.

@umireon
Created February 8, 2015 07:32
Show Gist options
  • Save umireon/ebe8f2e58cb3f771e04e to your computer and use it in GitHub Desktop.
Save umireon/ebe8f2e58cb3f771e04e to your computer and use it in GitHub Desktop.
interleaver and permutation
perms :: [Int] -> [[Int]]
perms [] = [[]]
perms (t:ts) = concatMap (interleave id t) (perms ts)
interleave :: ([Int] -> [Int]) -> Int -> [Int] -> [[Int]]
interleave f t [] = [f [t]]
interleave f t (x:xs) = (f (t:x:xs)) : interleave (f . (x:)) t xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment