Created
January 7, 2012 21:43
-
-
Save diegopacheco/1576148 to your computer and use it in GitHub Desktop.
Scala Pattern Matcher Recursion
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
| object RecursionMatcher extends App{ | |
| def factorial(i:BigInt):BigInt = i match { | |
| case _ if i == 1 => i | |
| case _ => i * factorial(i - 1) | |
| } | |
| for(i <- 1 to 10) printf("%s: %s\n", i, factorial(i)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment