Created
October 2, 2014 16:44
-
-
Save not-for-me/21cdf77eedc40ede238d to your computer and use it in GitHub Desktop.
Factorials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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