Solution to problem 41 in Julia

This commit is contained in:
David Doblas Jiménez 2021-09-11 20:11:32 +02:00
parent 675c03ef94
commit 3d157f1bfb

43
src/Julia/Problem041.jl Normal file
View File

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