/* Euler #50 in Picat. Problem 50 """ The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred. The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953. Which prime, below one-million, can be written as the sum of the most consecutive primes? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go => time(euler50). euler50 => N = 10000, Primes = [P : P in 1..N, prime(P)].to_array(), Found = 0, foreach(Len in 550..-1..21, Found == 0) foreach(Offset in 1..549, Found == 0, prime(sum([Primes[J] : J in Offset+1..Offset+Len]))) PP = sum([Primes[J] : J in Offset+1..Offset+Len]), if PP < 1000000 then Found := PP end end end, writeln(Found).