Skip to content

Instantly share code, notes, and snippets.

@Koitaro
Created April 22, 2010 11:29
Show Gist options
  • Save Koitaro/375102 to your computer and use it in GitHub Desktop.
Save Koitaro/375102 to your computer and use it in GitHub Desktop.
permutation, perm, powerSet
permutation :: [a] -> [[a]] | Eq a
permutation [] = [[]]
permutation xs = [[x:rest] \\ x <- xs, rest <- (permutation o filter ((<>) x)) xs]
perm :: [[a]] -> [[a]] | Eq a
perm [] = [[]]
perm [xs:xss] = [[x:rest] \\ x <- xs, rest <- (perm o map (filter ((<>) x))) xss]
powerSet :: [a] -> [[a]]
powerSet [] = [[]]
powerSet [x:xs] = flatten [[[x:ys],ys] \\ ys <- powerSet xs]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment