forked from ngiengkianyew/daily-coding-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_101.py
More file actions
31 lines (24 loc) · 724 Bytes
/
problem_101.py
File metadata and controls
31 lines (24 loc) · 724 Bytes
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
def is_prime(num, primes):
for prime in primes:
if prime == num:
return True
if not num % prime:
return False
return True
def get_primes(num):
limit = (num // 2) + 1
candidates = list()
primes = list()
for i in range(2, limit):
if is_prime(i, primes):
primes.append(i)
candidates.append((i, num - i))
new_candidates = list()
for first, second in candidates[::-1]:
if is_prime(second, primes):
primes.append(second)
new_candidates.append((first, second))
return new_candidates[-1]
assert get_primes(4) == (2, 2)
assert get_primes(10) == (3, 7)
assert get_primes(100) == (3, 97)