Reduce allocations and refactoring
This commit is contained in:
parent
4bac47687b
commit
bc5bd80a58
@ -1,4 +1,4 @@
|
|||||||
using Base:Integer
|
using Base: Integer
|
||||||
#=
|
#=
|
||||||
Created on 26 Jul 2021
|
Created on 26 Jul 2021
|
||||||
|
|
||||||
@ -10,13 +10,19 @@ https://projecteuler.net/problem=16 =#
|
|||||||
|
|
||||||
using BenchmarkTools
|
using BenchmarkTools
|
||||||
|
|
||||||
|
# function pow(n)
|
||||||
|
# return 2^BigInt(n)
|
||||||
|
# end
|
||||||
|
|
||||||
function Problem16()
|
function Problem16()
|
||||||
#=
|
#=
|
||||||
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
|
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? =#
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user