6 lines
236 B
Forth
6 lines
236 B
Forth
|
|
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
|