Project Euler Problem 20 Solution

n! means n x (n – 1) x … x 3 x 2 x 1

Find the sum of the digits in the number 100!

My solution in Ruby:

sum = 0
factorial = 1
for i in 1..100
  factorial = factorial * i
end
str = factorial.to_s
y = str.scan(/./)
y.each do |c|
  sum += c.to_i
end
puts sum

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.