-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb077.jl
46 lines (34 loc) · 828 Bytes
/
pb077.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
module Problem077
using Primes
using .Iterators
const cache = Dict{Tuple{Int,Int},Int}()
function f(n, i, primes)
return get!(cache, (n, i)) do
i == 0 && return 0
n == 0 && return 1
n < 0 && return 0
p = primes[i]
return f(n - p, i, primes) + f(n, i - 1, primes)
end
end
"""
problem077()
Problem 077 of Project Euler.
https://projecteuler.net/problem=077
Very similar to the previous problem...
"""
function problem077(N::Integer=5000)
empty!(cache)
pL = 10
primesL = primes(pL)
i = 1
for n in countfrom(2)
n == primesL[i] && (i += 1)
i == length(primesL) && (pL *= 10; primesL = primes(pL))
f(n, i - 1, primesL) > N && return n
end
end
export problem077
end # module Problem077
using .Problem077
export problem077