Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created Feb 26, 2013
Embed
What would you like to do?
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)
@kenrett
Copy link
Author

kenrett commented Feb 27, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment