Created
January 22, 2013 19:21
-
-
Save weskerfoot/4597501 to your computer and use it in GitHub Desktop.
generalizes permutations
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
select [] = [] | |
select (x : xs) = (x, xs) : map (fmap (x :)) (select xs) | |
perm2 ks = [[x,y] | (x, ys) <- select ks, y <- ys] | |
permute 2 xs = perm2 xs | |
permute n xs = join [[x : p | p <- (permute (n-1) ys)] | (x,ys) <- select xs] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment