forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp049.py
More file actions
32 lines (25 loc) · 787 Bytes
/
p049.py
File metadata and controls
32 lines (25 loc) · 787 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
32
#
# Solution to Project Euler problem 49
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import eulerlib
def compute():
LIMIT = 10000
isprime = eulerlib.list_primality(LIMIT - 1)
for base in range(1000, LIMIT):
if isprime[base]:
for step in range(1, LIMIT):
a = base + step
b = a + step
if a < LIMIT and isprime[a] and has_same_digits(a, base) \
and b < LIMIT and isprime[b] and has_same_digits(b, base) \
and (base != 1487 or a != 4817):
return str(base) + str(a) + str(b)
raise RuntimeError("Not found")
def has_same_digits(x, y):
return sorted(str(x)) == sorted(str(y))
if __name__ == "__main__":
print(compute())