Skip to content

Instantly share code, notes, and snippets.

@pjlowry
Last active December 11, 2015 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjlowry/4626419 to your computer and use it in GitHub Desktop.
Save pjlowry/4626419 to your computer and use it in GitHub Desktop.
big numbers!!!
def factorial(number)
if number < 0
"You can't take the factorial of a negative number"
elsif number == 0
1
else
(2..number).inject (:*)
end
end
puts "'#{factorial(0)}' should equal '1'."
puts "'#{factorial(5)}' should equal '120'."
puts "'#{factorial(-2)}' should equal 'You can't take the factorial of a negative number'."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment