Have I checked every consecutive subset of this list?

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2010-05-02T15:50:57Z Indexed on 2010/05/02 15:57 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

I'm trying to solve problem 50 on Project Euler. Don't give me the answer or solve it for me, just try to answer this specific question.

The goal is to find the longest sum of consecutive primes that adds to a prime below one million. I use wrote a sieve to find all the primes below n, and I have confirmed that it is correct. Next, I am going to check the sum of each subset of consecutive primes using the following method:

I have a empty list sums. For each prime number, I add it to each element in sums and check the new sum, then I append the prime to sums.

Here it is in python

primes = allPrimesBelow(1000000)
sums = []
for p in primes:
    for i in range(len(sums)):
        sums[i] += p
        check(sums[i])
    sums.append(p)

I want to know if I have called check() for every sum of two or more consecutive primes below one million

The problem says that there is a prime, 953, that can be written as the sum of 21 consecutive primes, but I am not finding it.

© Stack Overflow or respective owner

Related posts about python

Related posts about project-euler