dgerbs
3/14/2014 - 1:38 AM

Fun with Factorials

Fun with Factorials

# Factorial recursive

def factorial(number)
  if number == 1
    return 1
  else
    number * factorial(number - 1)
  end
end

# Factorial shorthand

def fact(n)
  (1..n).reduce(:*)
end