Last Updated: February 25, 2016
·
576
· harrisongrieve

Sum of digits in n!

A Ruby function to sum all digits of a given factorial n

def add_factorial(n)
  a = (1..(n.zero? ? 1 : n)).inject(:*).to_s().split(//)
  sum = 0
  a.each do |x|
    sum += x.to_i()
  end
  return sum
end