Euler 0036
The Problem:
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
Considerations and Approach:
We are going to look at every number between 1 and the upper limit, turn it into a string and verify if it is a palindrome in base 10.
If it is then we convert the number into a binary string representation (which we take off the first two letters of) and we check if that is palindromic.
If it is, then we add the number to the list of palindromes.
Then at the end we sum up the list of palindromes.
The Code:
upper_limit = 1000000
pals = []
for i in range(1,upper_limit):
str_i = str(i)
if str_i == str_i[::-1]:
bin_i = bin(i)[2:]
if bin_i == bin_i[::-1]:
print(i, bin_i)
pals += [i]
print(len(pals), sum(pals))