Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Created May 20, 2013 12:30
Show Gist options
  • Save ngpestelos/5611941 to your computer and use it in GitHub Desktop.
Save ngpestelos/5611941 to your computer and use it in GitHub Desktop.
Recursive factorial in Ruby
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