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

4 lines
138 B
Haskell
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
derangements xs = loop xs xs
where loop [] [] = [[]]
loop (h:hs) xs = [x:ys | x <- xs, x /= h, ys <- loop hs (delete x xs)]