Skip to content

Instantly share code, notes, and snippets.

@vmencik
Created January 17, 2013 08:52
Show Gist options
  • Save vmencik/4554648 to your computer and use it in GitHub Desktop.
Save vmencik/4554648 to your computer and use it in GitHub Desktop.
def factorial(n: Int): Int = {
@tailrec
def accumFactors(accumulator: Int, n: Int): Int =
if (n == 0) accumulator
else accumFactors(accumulator * n, n - 1)
accumFactors(1, n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment