Skip to content

Instantly share code, notes, and snippets.

@flakyfilibuster
Created October 5, 2012 21:07
Show Gist options
  • Save flakyfilibuster/3842416 to your computer and use it in GitHub Desktop.
Save flakyfilibuster/3842416 to your computer and use it in GitHub Desktop.
factorial
##########################
# => factorial iterative
##########################
def factorial_it(n)
return (1..n).inject(:*)
end
#puts factorial(10)
##########################
# => factorial recursive
##########################
def factorial_rec(n)
n == 0 ? 1 : n*factorial_rec(n-1)
end
#puts factorial_rec(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment