Skip to content

Instantly share code, notes, and snippets.

@reinh
Created May 27, 2010 18:40
Show Gist options
  • Save reinh/416176 to your computer and use it in GitHub Desktop.
Save reinh/416176 to your computer and use it in GitHub Desktop.
def factorial_recursive(n)
return 1 if n == 0 # base case
n *= factorial(n - 1) #recursion
end
def factorial_iterative(n)
(1..n).reduce(:*)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment