From 0a8c1398b58a0a01baaf9bd7daed20ef9a62c487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Doblas=20Jim=C3=A9nez?= Date: Tue, 9 Aug 2022 17:30:16 +0200 Subject: [PATCH] Solution to problem 63 in Julia --- src/Julia/Problem063.jl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Julia/Problem063.jl diff --git a/src/Julia/Problem063.jl b/src/Julia/Problem063.jl new file mode 100644 index 0000000..9cb0098 --- /dev/null +++ b/src/Julia/Problem063.jl @@ -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())