2022-10-16 16:03:50 +02:00

32 lines
729 B
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#=
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())