Solution to problem 63 in Julia

This commit is contained in:
David Doblas Jiménez 2022-08-09 17:30:16 +02:00
parent 286d1b564b
commit 0a8c1398b5

37
src/Julia/Problem063.jl Normal file
View File

@ -0,0 +1,37 @@
#=
Created on 09 Aug 2022
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 63 of Project Euler
https://projecteuler.net/problem=63
=#
using BenchmarkTools
function Problem63()
#=
The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the
9-digit number, 134217728=8^9, is a ninth power.
How many n-digit positive integers exist which are also an nth power?
=#
ans::Int8 = 0
# no need to go higher than 10, because 10**2 = 100
for number in 1:11
for pow in 1:31
if length(digits(number^pow)) == pow
ans += 1
end
end
end
return ans
end
println("Time to evaluate Problem $(lpad(63, 3, "0")):")
@btime Problem63()
println("")
println("Result for Problem $(lpad(63, 3, "0")): ", Problem63())