-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler_36.py
More file actions
43 lines (33 loc) · 873 Bytes
/
euler_36.py
File metadata and controls
43 lines (33 loc) · 873 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
33
34
35
36
37
38
39
40
41
42
43
def double_base():
million = range(1, 1000001)
b_million = []
for i in million:
b_million.append(int(str(bin(i))[2:]))
return b_million
def isPalindrome(number):
number_str = str(number)
index_b = 0
index_e = len(number_str)-1
max_index = len(number_str) / 2
while index_b < max_index:
if int(number_str[index_b]) != int(number_str[index_e]):
return 0
index_b += 1
index_e -= 1
return 1
def palindromes():
palinlist = []
for i in range(1, 1000001):
if isPalindrome(i):
palinlist.append(i)
return palinlist
def b_palindromes(pals):
b_pals = []
for i in pals:
b_num = int(str(bin(i))[2:])
if isPalindrome(b_num):
b_pals.append(i)
return b_pals
pal = palindromes()
my_b = b_palindromes(pal)
sum(my_b) = 872187