Created
July 5, 2009 05:33
-
-
Save hakobe/140847 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 _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