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

@ -42,7 +42,7 @@ function Problem019()
end end
println("Took: ") println("Took:")
@btime Problem019() @btime Problem019()
println("") println("")
println("Result for Problem $(lpad(19, 3, "0")): ", Problem019()) println("Result for Problem $(lpad(19, 3, "0")): ", Problem019())

View File

@ -4,12 +4,13 @@ Created on 03 Aug 2021
@author: David Doblas Jiménez @author: David Doblas Jiménez
@email: daviddoji@pm.me @email: daviddoji@pm.me
Solution for Problem 20 of Project Euler Solution for Problem 020 of Project Euler
https://projecteuler.net/problem=20 =# https://projecteuler.net/problem=20
=#
using BenchmarkTools using BenchmarkTools
function Problem20() function Problem020()
#= #=
n! means n × (n 1) × ... × 3 × 2 × 1 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: and the sum of the digits in the number 10! is:
3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. 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(digits(factorial(big(100))))
return sum(parse(Int8, d) for d::Char = string(fact))
end end
println("Time to evaluate Problem $(lpad(20, 3, "0")):") println("Took:")
@btime Problem20() @btime Problem020()
println("") println("")
println("Result for Problem $(lpad(20, 3, "0")): ", Problem20()) println("Result for Problem $(lpad(20, 3, "0")): ", Problem020())