-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem60.py
More file actions
33 lines (27 loc) · 1.01 KB
/
problem60.py
File metadata and controls
33 lines (27 loc) · 1.01 KB
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
# project euler problem 60
# http://projecteuler.net/problem=60
# Looking for better solutions
from ProjectEulerUtils import is_prime, prime_sieve
from itertools import combinations
def is_pair(n, m):
return is_prime(int(str(n) + str(m))) and is_prime(int(str(m) + str(n)))
def is_prime_group(it):
for n, m in combinations(it, 2):
if not is_pair(n, m):
return False
return True
primes = list(prime_sieve(10000))
def solve():
for n in primes:
if n == 5:
continue
for m in primes[primes.index(n):]:
if is_pair(n, m):
for x in primes[primes.index(m):]:
if is_prime_group([x, n, m]):
for y in primes[primes.index(x):]:
if is_prime_group([y, x, n, m]):
for z in primes[primes.index(y):]:
if is_prime_group([z, y, x, n, m]):
return sum([z, y, x, n, m])
print solve()