Overview

 

Question

\(n!\) means \(n \times (n − 1) \times ... \times 3 \times 2 \times 1\).

For example, \(10!\) = 10 9 ... 3 2 1 = 3628800, and the sum of the digits in the number \(10!\) is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number \(100!\).

click for answer

648

Solutions

 

Ruby

 factorialSum.rb https://raw.github.com/addamh/euler/master/020/factorialSum.rb download
#!/usr/bin/env ruby

puts 100.downto(1).to_a.reduce(&:*).to_s.each_char.to_a.map!{|k| k.to_i}.reduce(:+)
$ time ruby factorialSum.rb
real	0m0.455s
user	0m0.431s
sys	0m0.021s