let rec aux pre post = seq {
| h::t -> yield (pre @ y::post)
yield! aux (pre @ [h]) t }
let rec getAllPerms = function
| h::t -> getAllPerms t |> Seq.collect (distrib h)
getAllPerms [1;2;3] |> Seq.toList |> printfn "%A"
getAllPerms [1;2;3;4;5] |> Seq.toList |> printfn "%A"