fork(2) download
  1. let rec combinations n l =
  2. match n, l with
  3. | 0, _ -> [[]]
  4. | _, [] -> []
  5. | k, (x::xs) -> List.map ((@) [x]) (combinations (k-1) xs) @ combinations k xs
  6.  
  7. let rec cross acc xs =
  8. match xs with
  9. | h :: t -> cross ([ for e in t -> h, e] @ acc) t
  10. | [] -> acc
  11.  
  12. let solve n (lst : int list) =
  13. [ for e in 1..n -> combinations e lst ]
  14. |> Seq.collect id
  15. |> Seq.groupBy List.sum
  16. |> Seq.filter (fun (_,e) -> Seq.length e > 1)
  17. |> Seq.collect (snd >> Seq.toList >> cross [])
  18. |> Seq.toList
  19.  
  20. solve 6 [1..12]
  21. |> List.rev |> List.head
  22. |> printfn "%A"
Success #stdin #stdout 0.34s 29936KB
stdin
Standard input is empty
stdout
([5; 8; 9; 10; 11; 12], [6; 7; 9; 10; 11; 12])