Skip to content

Instantly share code, notes, and snippets.

@not-for-me
Created October 2, 2014 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save not-for-me/21cdf77eedc40ede238d to your computer and use it in GitHub Desktop.
Save not-for-me/21cdf77eedc40ede238d to your computer and use it in GitHub Desktop.
Factorials
def factorial(n: Int): Int = {
def loop(acc: Int, n: Int): Int =
if (n == 0) acc
else loop(acc*n, n-1)
loop(1, n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment