Project Euler 10: (Iron)Python
- by Ben Griswold
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 10.
As always, any feedback is welcome.
# Euler 10
# http://projecteuler.net/index.php?section=problems&id=10
# The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
# Find the sum of all the primes below two million.
import time
start = time.time()
def primes_to_max(max):
primes, number = [2], 3
while number < max:
isPrime = True
for prime in primes:
if number % prime == 0:
isPrime = False
break
if (prime * prime > number):
break
if isPrime:
primes.append(number)
number += 2
return primes
primes = primes_to_max(2000000)
print sum(primes)
print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')