32 lines
729 B
Julia
32 lines
729 B
Julia
#=
|
||
Created on 03 Aug 2021
|
||
|
||
@author: David Doblas Jiménez
|
||
@email: daviddoji@pm.me
|
||
|
||
Solution for Problem 20 of Project Euler
|
||
https://projecteuler.net/problem=20 =#
|
||
|
||
using BenchmarkTools
|
||
|
||
function Problem20()
|
||
#=
|
||
n! means n × (n − 1) × ... × 3 × 2 × 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! =#
|
||
|
||
fact::BigInt = factorial(big(100))
|
||
|
||
return sum(parse(Int8, d) for d::Char = string(fact))
|
||
end
|
||
|
||
|
||
println("Time to evaluate Problem $(lpad(20, 3, "0")):")
|
||
@btime Problem20()
|
||
println("")
|
||
println("Result for Problem $(lpad(20, 3, "0")): ", Problem20())
|