Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created July 5, 2009 05:33
Show Gist options
  • Select an option

  • Save hakobe/140847 to your computer and use it in GitHub Desktop.

Select an option

Save hakobe/140847 to your computer and use it in GitHub Desktop.
def factorial(n: Int) :Int = {
def _factorial(n: Int, result: Int) :Int = {
if (n <= 0) result else _factorial(n-1, n * result)
}
_factorial(n, 1)
}
println(factorial(10000))
def simple_factorial(n: Int) :Int = {
if (n <= 0) 1 else n * simple_factorial(n-1)
}
println(simple_factorial(10000)) // => java.lang.StackOverflowError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment