-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob_49.py
79 lines (61 loc) · 1.47 KB
/
prob_49.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 13 20:49:28 2017
@author: Rohit Maurya
"""
#this program does answer, but algo for this program sucks.
from timeit import default_timer as timer
start = timer()
def isprime(n):
"""Returns True if n is prime."""
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def similar(n,m):
str_n = str(n)
str_m = str(m)
if sorted(str_n) == sorted(str_m):
return True
else:
return False
def main():
"""Main Program"""
L = []
for i in range(1000,9999):
if isprime(i):
L.append(i)
diff = [0,0]
l = [0,0,0]
for i in L:
for j in L:
if j < i or j==i:
pass
else:
if similar(i,j):
l.append(i)
l.append(j)
diff.append(j-i)
if diff[-1] == 2*diff[-2]:
print(l[-1],l[-2],l[-3])
break
if diff[-1] == 2*diff[-2]:
break
if __name__ == '__main__':
main()
end = timer()
time_taken = (end-start)*1000
print("Time taken to run this program:%d ms"%time_taken)