Skip to content

Instantly share code, notes, and snippets.

@stephenLee
Created September 13, 2012 13:34
Show Gist options
  • Save stephenLee/3714308 to your computer and use it in GitHub Desktop.
Save stephenLee/3714308 to your computer and use it in GitHub Desktop.
tail-recursive version of factorial
def factorial(n: Int) = {
def factorial1(n: Int, multi: Int): Int = {
if (n == 0) multi
else factorial1(n-1, multi*n)
}
factorial1(n, 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment