fn isPrime(n: Int): Bool = if n < 2 then false else isPrimeHelper(n, 2)

fn isPrimeHelper(n: Int, i: Int): Bool = if i * i > n then true else if n % i == 0 then false else isPrimeHelper(n, i + 1)

fn findPrimes(count: Int): Unit with {Console} = findPrimesHelper(2, count)

fn findPrimesHelper(current: Int, remaining: Int): Unit with {Console} =
    if remaining <= 0 then () else if isPrime(current) then {
    Console.print(toString(current))
    findPrimesHelper(current + 1, remaining - 1)
} else findPrimesHelper(current + 1, remaining)

fn main(): Unit with {Console} = {
    Console.print("First 20 prime numbers:")
    findPrimes(20)
}

let output = run main() with {}
