Created
February 8, 2015 07:32
-
-
Save umireon/ebe8f2e58cb3f771e04e to your computer and use it in GitHub Desktop.
interleaver and permutation
This file contains hidden or 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
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