-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem36.py
More file actions
54 lines (36 loc) · 1.12 KB
/
Copy pathproblem36.py
File metadata and controls
54 lines (36 loc) · 1.12 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
import time
def calculate_time(func):
def inner1(*args, **kwargs):
begin = time.time()
returned_value = func(*args, **kwargs)
end = time.time()
print("Total time taken in : ", func.__name__, end - begin)
return returned_value
return inner1
#########################################################################3
def is_palindrome(n):
n = str(n)
count = 0
for i in range (0, int(len(n)/2)):
if n[i] == n[len(n) - 1 - i]:
count += 1
return count == int(len(n)/2)
def test():
print(is_palindrome(585))
print(bin(585)[2:])
print(is_palindrome(bin(585)))
print(is_palindrome(123421))
#########################################################################3
@calculate_time
def main():
upper = 1000000
sum36 = 0
for i in range (0, upper):
if is_palindrome(i) and is_palindrome(bin(i)[2:]):
print("{}={}_2".format(i, bin(i)[2:]))
sum36 += i
print(sum36)
return 0
if __name__ == "__main__":
main()
# test()