Project Euler 7: (Iron)Python
- by Ben Griswold
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 7.
As always, any feedback is welcome.
# Euler 7
# http://projecteuler.net/index.php?section=problems&id=7
# By listing the first six prime numbers: 2, 3, 5, 7,
# 11, and 13, we can see that the 6th prime is 13. What
# is the 10001st prime number?
import time
start = time.time()
def nthPrime(nth):
primes = [2]
number = 3
while len(primes) < nth:
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[nth - 1]
print nthPrime(10001)
print "Elapsed Time:", (time.time() - start) * 1000, "millisecs"
a=raw_input('Press return to continue')