This repository was archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem049.py
More file actions
63 lines (47 loc) · 1.51 KB
/
Copy pathproblem049.py
File metadata and controls
63 lines (47 loc) · 1.51 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases
by 3330, is unusual in two ways:
(i) each of the three terms are prime, and,
(ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes,
exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this
sequence?
"""
from prime import Primes
def is_permutation(original, new):
"""is_permutation returns True if the two numbers are permutations of each
other. That means they have the same digits in the same amount. Otherwise
is_permutation returns False.
>>> is_permutation(2392, 2239)
True
>>> is_permutation(2392, 239)
False
"""
original = list(str(original))
original.sort()
new = list(str(new))
new.sort()
return original == new
def main():
"""
>>> main()
296962999629
148748178147
"""
lower_limit = 1000
upper_limit = 10000
primes = Primes(lower_limit, upper_limit)
candidates = set(primes)
while len(candidates) > 0:
prime = candidates.pop()
num2 = prime + 3330
num3 = num2 + 3330
if (
num2 in primes and is_permutation(prime, num2) and
num3 in primes and is_permutation(prime, num3)
):
print(str(prime) + str(num2) + str(num3))
if __name__ == "__main__":
import doctest
doctest.testmod()