Skip to content

Instantly share code, notes, and snippets.

@albertein
Created January 31, 2013 18:18
Show Gist options
  • Save albertein/4684967 to your computer and use it in GitHub Desktop.
Save albertein/4684967 to your computer and use it in GitHub Desktop.
Recursive factorial
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