RosettaCodeData/Task/Permutations/Haskell/permutations-4.hs
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

5 lines
249 B
Haskell

permutations :: [a] -> [[a]]
permutations = foldr (concatMap . insertEverywhere) [[]]
where insertEverywhere :: a -> [a] -> [[a]]
insertEverywhere x [] = [[x]]
insertEverywhere x l@(y:ys) = (x:l) : map (y:) (insertEverywhere x ys)