My solutions to the problems found at Project Euler.

Jump to: | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 20 | 21 | 22 | 25 | 3-2 |

Problem 7


#! /usr/bin/python
# Problem: Find the 10001nth Prime.
#
# Solution: Define a process to find a prime (a number not divisible by anything but itself.)

def nth_prime(n):
  if n == 1:
    return 2
  if n == 2:
    return 3
  
  primes = [2,3]
  testing = 3
  while len(primes) < n:
      
    found = True
    for prime in primes[1:]:
      if testing % prime == 0:
        found = False
        break
        
    if found:
      primes.append(testing)
    
    testing += 2
  
  return primes
  
if __name__ == "__main__":
  primes = nth_prime(10001)
  print primes.pop()

jb