Skip to content

Instantly share code, notes, and snippets.

@nobsun
Created July 31, 2015 13:36
Show Gist options
  • Save nobsun/ae8ad155d20fa477abb1 to your computer and use it in GitHub Desktop.
Save nobsun/ae8ad155d20fa477abb1 to your computer and use it in GitHub Desktop.
perms :: [a] -> [[a]]
perms [] = [[]]
perms xs@(_:_) = concat (zipWith prefix xs (map perms (shorts xs)))
perms :: [a] -> [[a]]
perms [] = [[]]
perms xs@(_:_) = concat (zipWiht prefix xs (map perms (shorts xs)))
prefix :: a -> [[a]] -> [[a]]
prefix = undefined
shorts :: [a] -> [[a]]
shorts = undefined
prefix x = map (x:)
shorts xs = unfoldr phi ([],xs)
where
phi (_,[]) = Nothing
phi (ys,z:zs) = Just (ys++zs,(ys++[z],zs))
perms :: [a] -> [[a]]
perms [] = [[]]
perms xs@(_:_) = concat (zipWiht prefix xs (map perms (shorts xs)))
prefix :: a -> [[a]] -> [[a]]
prefix x = map (x:)
shorts :: [a] -> [[a]]
shorts xs = unfoldr phi ([],xs)
where
phi (_,[]) = Nothing
phi (ys,z:zs) = Just (ys++zs,(ys++[z],zs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment