Skip to content

Commit

Permalink
Changed P10 to use a basic sieve
Browse files Browse the repository at this point in the history
Still too slow
  • Loading branch information
James Raikes authored and James Raikes committed Jul 15, 2016
1 parent 238f58e commit d07c753
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions problem10.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'''Project Euler Problem 10
Find the sum of every prime under 2 million'''
import problem7 as p7
Find the sum of every prime under 2 million
v2, use a basic sieve of Eratosthenes'''

def sieve(upper):
'''Return every prime below a given value'''
prime_list = []
int_list = list(range(2,upper))
while int_list:
prime_list.append(int_list[0])
int_list = [x for x in int_list if x % prime_list[-1]]
return prime_list

def prime_sum(upper):
i = 1
p_sum = 0
current_prime = 0
while True:
current_prime = p7.prime_generator(i)
if current_prime >= upper:
break
p_sum += current_prime
i += 1
return p_sum


def main():
print(prime_sum(10000))
print(sum(sieve(60000)))


if __name__ == "__main__":
Expand Down

0 comments on commit d07c753

Please sign in to comment.