Created
February 26, 2013 23:45
-
-
Save kenrett/5043466 to your computer and use it in GitHub Desktop.
This file contains 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 == 0 | |
return 1 | |
end | |
counter = 0 | |
array = [] | |
while n >= counter | |
n.times do |i| | |
array << i *= (n-counter) | |
end | |
counter += 1 | |
end | |
print array | |
end | |
puts factorial(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def factorial(n)
if n == 0
return 1
end
counter = 0
array = []
sum = 1
while n >= counter
array << sum *= (n-counter)
counter += 1
end
puts array.max
end