Created
January 31, 2013 18:18
-
-
Save albertein/4684967 to your computer and use it in GitHub Desktop.
Recursive factorial
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) # For n >= 1 | |
return n if n == 1 #Base case, recursion ends here | |
return n * factorial(n - 1) #Recursive solution, multiply the current number by the factorial of the previous number | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment