fn factorial(n: Int): Int = if n <= 1 then 1 else n * factorial(n - 1)

fn factorialTail(n: Int, acc: Int): Int = if n <= 1 then acc else factorialTail(n - 1, n * acc)

fn factorial2(n: Int): Int = factorialTail(n, 1)

fn main(): Unit with {Console} = {
    Console.print("Factorial examples:")
    Console.print("5! = " + toString(factorial(5)))
    Console.print("10! = " + toString(factorial(10)))
    Console.print("20! = " + toString(factorial2(20)))
}

let output = run main() with {}
