RosettaCodeData/Task/Permutations-Derangements/Haskell/permutations-derangements-2.hs

4 lines
138 B
Haskell
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
derangements xs = loop xs xs
where loop [] [] = [[]]
loop (h:hs) xs = [x:ys | x <- xs, x /= h, ys <- loop hs (delete x xs)]