-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem51.py
80 lines (51 loc) · 1.94 KB
/
problem51.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import time
from mymodule import calculate_time
from mymodule import is_prime
from itertools import combinations
#########################################################################3
def findsubsets(s, n):
return list(combinations(s, n))
def test():
num = '56723'
slices = [i for i in range (0, len(num) - 1)]
mask = findsubsets(slices, len(num)-1)
print(mask)
for e in mask:
temp = num
print("new family:")
for i in range (0, 10):
for k in e:
temp = temp[:k] + str(i) + temp[k+1:]
print(temp)
#########################################################################3
@calculate_time
def main():
index = 11
start_sequence = 0 #store the first of sequences, also result
num = 8
while True:
slices = [i for i in range (0, len(str(index)) - 1)]
for j in range(1, len(str(index))):
mask = findsubsets(slices, j) # get all the ways to replace digits with *
for e in mask:
temp = str(index)
count = 0
sequences = []
for i in range (0, 10):
for k in e:
temp = temp[:k] + str(i) + temp[k+1:]
if temp[0] == '0':
continue # ignore when replace first digit with 0
if (is_prime(int(temp))):
count += 1
sequences.append(temp)
if count == num:
print("Found: {}, e={}".format(str(index), e))
print(sequences)
print(sequences[0])
return 0
index += 2
return 0
if __name__ == "__main__":
main()
#test()