Created
May 20, 2013 12:30
-
-
Save ngpestelos/5611941 to your computer and use it in GitHub Desktop.
Recursive factorial in Ruby
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) | |
if (n < 2) | |
n | |
else | |
n * factorial(n - 1) | |
end | |
end | |
puts factorial(0) | |
puts factorial(1) | |
puts factorial(2) | |
puts factorial(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment