Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created February 26, 2013 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenrett/5043466 to your computer and use it in GitHub Desktop.
Save kenrett/5043466 to your computer and use it in GitHub Desktop.
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