Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def factorial(n: Int): Int = {
n match {
case n if n <= 0 => 1
case n => n * factorial(n - 1)
}
}
println(factorial(100))
def factorial(n: Int): Int = {
def go(n: Int, acc: Int): Int =
if (n <= 0) acc
else go(n - 1, n*acc)
go(n, 1)
}
println(factorial(100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment