diff --git a/src/Julia/Problem041.jl b/src/Julia/Problem041.jl new file mode 100644 index 0000000..412242e --- /dev/null +++ b/src/Julia/Problem041.jl @@ -0,0 +1,43 @@ +#= +Created on 11 Sep 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for Problem 41 of Project Euler +https://projecteuler.net/problem=41 +=# + +using BenchmarkTools +using Primes + +function is_pandigital(number) + number_ = join(sort(digits(number))) + check = join([i for i in 1:length(digits(number))]) + if number_ == check + return true + end + return false +end + +function Problem41() + #= + We shall say that an n-digit number is pandigital if it makes + use of all the digits 1 to n exactly once. For example, 2143 is + a 4-digit pandigital and is also prime. + + What is the largest n-digit pandigital prime that exists? + =# + + for ans in 7654321:-1:1 + if is_pandigital(ans) & isprime(ans) + return ans + end + end +end + + +println("Time to evaluate Problem 41:") +@btime Problem41() +println("") +println("Result for Problem 41: ", Problem41())