http://projecteuler.net/index.php?section=problems&id=50
どうしても素数列の遅延評価ができない。
open Arithmetic let N = pown 10 6 let primes = Primes.make_primes N let rec calc_max_list a s = let h = List.head a let t = List.tail a if s < h then [] else h :: (calc_max_list t (s - h)) let max_prime_sum a = let rec max_prime_sum' a s = if s <= 1 then [] else if Primes.is_prime s then a else max_prime_sum' (List.tail a) (s - List.head a) max_prime_sum' a (List.sum a) let max_and_prime a = let b = List.rev (calc_max_list a N) let c = max_prime_sum b (List.length b, c) let solve () = let rec solve' a b = let m, c = max_and_prime a if m < List.length b then b else solve' (List.tail a) (if List.length c > List.length b then c else b) List.sum (solve' primes []) printfn "%d" (solve())