Refactoring
This commit is contained in:
parent
5a2ad49902
commit
4a960cf1ad
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user