Problem 36
Python
1def get_bin_num(num):
2 temp_num = num
3 binary = ""
4 while temp_num != 0:
5 binary += (str(temp_num % 2))
6 temp_num //= 2
7 return binary
8
9def is_palin(num):
10 if num == num[::-1]:
11 return True
12 return False
13
14def main():
15 sum_palin = 0
16 for i in range(1, 1000000):
17 bin_num = get_bin_num(i)
18 if is_palin(bin_num) and is_palin(str(i)):
19 sum_palin += i
20 print(sum_palin)
21
22if __name__ == '__main__':main()