Skip to content

Instantly share code, notes, and snippets.

@lkrych
Created October 11, 2016 18:40
Show Gist options
  • Save lkrych/ed30bd616a19cb5ccf0b23dbcb7a50b4 to your computer and use it in GitHub Desktop.
Save lkrych/ed30bd616a19cb5ccf0b23dbcb7a50b4 to your computer and use it in GitHub Desktop.
Factorial function in ruby
def factorial(n)
if n <= 0
puts "sorry I only compute the factorial for positive numbers"
return
else
@product = 1
(1..n).each do |number|
@product *= number
end
return @product
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment