020 Factorial digit sum.sf 343 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # Find the sum of the digits in the number 100!
  6. # https://projecteuler.net/problem=20
  7. # Runtime: 0.110s
  8. var n = 100!
  9. say +(^n.len).map { |i| n.digit(i) }.sum
  10. # Alternatively:
  11. say 100!.digits.sum
  12. # Alternatively 2:
  13. say 100!.sumdigits