Refactoring

This commit is contained in:
David Doblas Jiménez 2023-04-11 19:25:39 +02:00
parent 5a2ad49902
commit 4a960cf1ad
2 changed files with 11 additions and 11 deletions

View File

@ -4,12 +4,13 @@ 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 =#
Solution for Problem 020 of Project Euler
https://projecteuler.net/problem=20
=#
using BenchmarkTools
function Problem20()
function Problem020()
#=
n! means n × (n 1) × ... × 3 × 2 × 1
@ -17,15 +18,14 @@ function Problem20()
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! =#
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))
return sum(digits(factorial(big(100))))
end
println("Time to evaluate Problem $(lpad(20, 3, "0")):")
@btime Problem20()
println("Took:")
@btime Problem020()
println("")
println("Result for Problem $(lpad(20, 3, "0")): ", Problem20())
println("Result for Problem $(lpad(20, 3, "0")): ", Problem020())