Solution to problem 41 in Julia
This commit is contained in:
parent
675c03ef94
commit
3d157f1bfb
43
src/Julia/Problem041.jl
Normal file
43
src/Julia/Problem041.jl
Normal 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())
|
Loading…
x
Reference in New Issue
Block a user