35 lines
693 B
Plaintext
35 lines
693 B
Plaintext
cool_number: Int
|
|
cool_number = 1312
|
|
|
|
main: Int
|
|
main = nth_prime cool_number
|
|
|
|
nth_prime: Int -> Int
|
|
nth_prime n =
|
|
if n == 1
|
|
then 2
|
|
else nth_prime_helper (n - 1) 3
|
|
|
|
nth_prime_helper: Int, Int -> Int
|
|
nth_prime_helper remaining_primes next_to_try =
|
|
if is_prime next_to_try
|
|
then
|
|
if remaining_primes < 2
|
|
then next_to_try
|
|
else nth_prime_helper (remaining_primes - 1) (next_to_try + 2)
|
|
else nth_prime_helper remaining_primes (next_to_try + 2)
|
|
|
|
is_prime: Int -> Int
|
|
is_prime x =
|
|
if x % 2 == 0
|
|
then 0
|
|
else is_prime_helper x 3
|
|
|
|
is_prime_helper: Int, Int -> Int
|
|
is_prime_helper x try =
|
|
if try * try > x
|
|
then 1
|
|
else if x % try == 0
|
|
then 0
|
|
else is_prime_helper x (try + 2)
|