Divrem does not allocate
This commit is contained in:
parent
32a5e5c01e
commit
2cb8ed1637
@ -11,8 +11,12 @@ https://projecteuler.net/problem=30
|
|||||||
using BenchmarkTools
|
using BenchmarkTools
|
||||||
|
|
||||||
function power_digit_sum(pow, n)
|
function power_digit_sum(pow, n)
|
||||||
# return sum(c^pow for c in reverse(digits(n)))
|
s = 0
|
||||||
return sum(c->c^pow, digits(n))
|
while n > 0
|
||||||
|
(n, r) = divrem(n, 10)
|
||||||
|
s += r^pow
|
||||||
|
end
|
||||||
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
function Problem30()
|
function Problem30()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user