fork download
  1. let rec perm (ls :'a list) (n :int) :'a list list =
  2. if n = 0 then [[]]
  3. else
  4. [for x in ls do
  5. for xs in perm (ls |> List.filter (fun a -> a<>x)) (n-1) do
  6. yield x::xs]
  7.  
  8. for [a;b;c;d;e] in perm [1 ..15] 5 do
  9. if [a; b; c; d; e
  10. a+b; b+c; c+d; d+e; e+a
  11. a+b+c; b+c+d; c+d+e; d+e+a; e+a+b
  12. a+b+c+d; b+c+d+e; c+d+e+a; d+e+a+b; e+a+b+c
  13. a+b+c+d+e] |> List.sort = [1..21] then
  14. printfn "%A" (a,b,c,d,e)
Success #stdin #stdout 1.36s 151040KB
stdin
Standard input is empty
stdout
(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)