let rec perm (ls :'a list) (n :int) :'a list list = if n = 0 then [[]] else [for x in ls do for xs in perm (ls |> List.filter (fun a -> a<>x)) (n-1) do yield x::xs] for [a;b;c;d;e] in perm [1 ..15] 5 do if [a; b; c; d; e a+b; b+c; c+d; d+e; e+a a+b+c; b+c+d; c+d+e; d+e+a; e+a+b a+b+c+d; b+c+d+e; c+d+e+a; d+e+a+b; e+a+b+c a+b+c+d+e] |> List.sort = [1..21] then printfn "%A" (a,b,c,d,e)
Standard input is empty
(1, 3, 10, 2, 5) (1, 5, 2, 10, 3) (2, 5, 1, 3, 10) (2, 10, 3, 1, 5) (3, 1, 5, 2, 10) (3, 10, 2, 5, 1) (5, 1, 3, 10, 2) (5, 2, 10, 3, 1) (10, 2, 5, 1, 3) (10, 3, 1, 5, 2)