-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path037.jl
43 lines (38 loc) · 758 Bytes
/
037.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# https://projecteuler.net/problem=037
using Primes
function nextprime(n::Int)
(n == 0 || n == 1) && return 2
len = 0
p = Vector{Int}()
while len == 0
n += 1
p = primes(n, n+1)
len = length(p)
end
return p[end]
end
function istruncprime(n::Int)
!isprime(n) && return false
d = digits(n)
len = length(d)
s = 0
for j in 1:len
s += isprime(sum( d[i]*10^(i-1) for i in 1:j ))
s += isprime(sum( d[end-i+1]*10^(j-i) for i in 1:j ))
end
s == 2len ? true : false
end
function g()
s = 0
p = 0
n = 9
while s < 11
n = nextprime(n)
if istruncprime(n)
s += 1
p += n
end
end
return p
end
g() |> println