From bc5bd80a587e3da604ebeaf8d89689828f390ca2 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Wed, 12 Oct 2022 21:07:52 +0200 Subject: [PATCH] Reduce allocations and refactoring --- src/Julia/Problems001-050/Problem016.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Julia/Problems001-050/Problem016.jl b/src/Julia/Problems001-050/Problem016.jl index 4103558..c9d83d1 100644 --- a/src/Julia/Problems001-050/Problem016.jl +++ b/src/Julia/Problems001-050/Problem016.jl @@ -1,4 +1,4 @@ -using Base:Integer +using Base: Integer #= Created on 26 Jul 2021 @@ -10,13 +10,19 @@ https://projecteuler.net/problem=16 =# using BenchmarkTools +# function pow(n) +# return 2^BigInt(n) +# end + function Problem16() #= 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? =# - n = 1000 - return sum(parse(Int, d) for d in string(2^BigInt(n))) + + n::Int16 = 1_000 + + return sum(digits(2^BigInt(n))) end