Divrem does not allocate

This commit is contained in:
David Doblas Jiménez 2021-08-25 19:48:07 +02:00
parent 32a5e5c01e
commit 2cb8ed1637

View File

@ -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()