Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Created January 22, 2013 19:21
Show Gist options
  • Save weskerfoot/4597501 to your computer and use it in GitHub Desktop.
Save weskerfoot/4597501 to your computer and use it in GitHub Desktop.
generalizes permutations
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