summaryrefslogtreecommitdiff
path: root/049.py
blob: 1cb2fbf5710f1f616c800978247cdb8526628ba9 (plain)
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
from common import sieve, permutation

primes = sieve(10000).primes()
primes2 = [ x for x in primes if x > 1000 ]
primes2.sort()

end = False
ignore = 1487
result = []

for p in primes2:
	for q in primes2:
		if p == q:
			continue
		if permutation(p, q):
			new = 0
			if q > p:
				diff = q - p
				new = q + diff
			else:
				diff = p - q
				new = p + diff

			if new in primes and permutation(q, new) and not permutation(ignore, p):
				result += [p, q, new]
				end = True
		if end:
			break
	if end:
		break

result.sort()
print str(result[0]) + str(result[1]) + str(result[2])