<reponame>josienb/project_euler
# Project Euler
# 7 - 10001st prime

# 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 10 001st prime number?

def calculate_nth_prime(n):
    number = 1
    prime_counter = 0
    while prime_counter < n:
        if isprime(number):
            prime_counter = prime_counter + 1
        if prime_counter == n:
            break
        number = number + 1
    return number

def isprime(n):
    '''check if integer n is a prime'''
    # make sure n is a positive integer
    n = abs(int(n))
    # 0 and 1 are not primes
    if n < 2:
        return False
    # 2 is the only even prime number
    if n == 2:
        return True
    # all other even numbers are not primes
    if not n & 1:
        return False
    # range starts with 3 and only needs to go up the squareroot of n
    # for all odd numbers
    for x in range(3, int(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True

print calculate_nth_prime(10001)

# Project Euler
# 7 - 10001st prime

# 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 10 001st prime number?

def calculate_nth_prime(n):
    number = 1
    prime_counter = 0
    while prime_counter < n:
        if isprime(number):
            prime_counter = prime_counter + 1
        if prime_counter == n:
            break
        number = number + 1
    return number

def isprime(n):
    '''check if integer n is a prime'''
    # make sure n is a positive integer
    n = abs(int(n))
    # 0 and 1 are not primes
    if n < 2:
        return False
    # 2 is the only even prime number
    if n == 2:
        return True
    # all other even numbers are not primes
    if not n & 1:
        return False
    # range starts with 3 and only needs to go up the squareroot of n
    # for all odd numbers
    for x in range(3, int(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True

print calculate_nth_prime(10001)
# Project Euler # 7 - 10001st prime # 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 10 001st prime number? check if integer n is a prime # make sure n is a positive integer # 0 and 1 are not primes # 2 is the only even prime number # all other even numbers are not primes # range starts with 3 and only needs to go up the squareroot of n # for all odd numbers