Amo/sample-initial.amo

35 lines
693 B
Plaintext
Raw Normal View History

cool_number: Int
2022-04-25 17:05:59 +00:00
cool_number = 1312
2022-04-24 01:52:30 +00:00
main: Int
2022-04-25 17:05:59 +00:00
main = nth_prime cool_number
2022-04-06 13:23:46 +00:00
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)