5 lines
236 B
FSharp
5 lines
236 B
FSharp
let permutations xs =
|
|
let rec insert x = function
|
|
| [] -> [[x]]
|
|
| head :: tail -> (x :: (head :: tail)) :: (List.map (fun l -> head :: l) (insert x tail))
|
|
List.fold (fun s e -> List.collect (insert e) s) [[]] xs
|