(19 votes, average: 5.00 out of 5)

## Project Euler 36: Find the sum of all numbers less than one million, which are palindromic in both base 10 and base 2

#### Problem Description

The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)

#### Analysis

Since leading zeros are not allowed, the top and bottom bits for binary numbers have to be one in order to be palindromic. This eliminates even numbers from consideration.

Further, it is desirable to only consider palindromic numbers as it reduces the search space from 500,000 to 1,114.

#### Project Euler 36 Solution

Runs < 0.001 seconds in Python 2.7.

Use this link to get the Project Euler 36 Solution Python 2.7 source.

#### Afterthoughts

• Functions `pal_list, is_palindromic` are listed in Common Functions and Routines for Project Euler
• Reference: The On-Line Encyclopedia of Integer Sequences (OEIS) A007632: Numbers that are palindromic in bases 2 and 10.
• Results <1,000,000,000,000, i.e., 12 or fewer digits (reduced to 1,111,114 palindromic odd numbers):
• sum([1, 3, 5, 7, 9, 33, 99, 313, 585, 717, 7447, 9009, 15351, 32223, 39993, 53235, 53835, 73737, 585585, 1758571, 1934391, 1979791, 3129213, 5071705, 5259525, 5841485, 13500531, 719848917, 910373019, 939474939, 1290880921, 7451111547, 10050905001, 18462126481, 32479297423, 75015151057, 110948849011, 136525525631]) = 394832891346
• 6.8 sec in python, 3.1 in pypy
Project Euler 36 Solution last updated