-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb070.jl
50 lines (37 loc) · 822 Bytes
/
pb070.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
44
45
46
47
48
49
50
module Problem070
using ..ProjectEulerLibrary
const digitsn = Int[]
const digitsm = Int[]
function digitpermutation(n, m)
ln = ndigits(n)
lm = ndigits(m)
ln == lm || return false
resize!(digitsn, ln)
resize!(digitsm, lm)
digits!(digitsn, n)
digits!(digitsm, m)
sort!(digitsn)
sort!(digitsm)
return digitsn == digitsm
end
"""
problem070()
Problem 070 of Project Euler.
https://projecteuler.net/problem=070
"""
function problem070(N::Integer=10^7)
phi = totients(N)
min_n = 1
min_phi = 0
for n in 2:N-1
n * min_phi < min_n * phi[n] || continue
digitpermutation(n, phi[n]) || continue
min_n = n
min_phi = phi[n]
end
return min_n
end
export problem070
end # module Problem070
using .Problem070
export problem070