**From New Scientist #2864, 12th May 2012** [link]

I have before me a number, which when written in binary is palindromic and has n digits. If I told you the value of n, and you wrote a list of all the possible palindromic binary numbers of length n, your list would have n numbers in it.

If your list was in ascending numeric order, and I told you the difference between my number and the next higher number in the list, you would be able to identify my number.

What is my number, in decimal form?

[enigma1697]

### Like this:

Like Loading...

Here’s my initial attempt in Python. It runs in 39ms.

Solution:The number is 189.Initially I wrote this only to check even-length binary palindromes, and then added in odd-length binary palindromes later. Although the answer can not be an odd-length palindrome as they must always come in pairs, so the total number of binary palindromes for a given odd-length must always be even, so I could have stuck with my original code. (Just take out all the

qsstuff). It doesn’t make any difference to the run time anyway.A little bit more analysis tells you exactly what the only possibility for n is.

Here’s a variation that only checks even length binary palindromes.

Here is my version

And here is a better version:

Solved the New Scientist Enigma Problem number 1697

The answer in decimal form is 189

The binary palindrome is 10111101

my solution as a picture

I did pretty much the same as Steven, but using excel:

https://www.dropbox.com/s/a12s74kgdqfspia/Enigma%201697.xls

Hardly seemed worth writing any Python code this week.