### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,149)
- misc (2)
- project euler (2)
- puzzle (38)
- site news (44)
- tantalizer (40)
- teaser (3)

### Site Stats

- 175,242 hits

Advertisements

Programming Enigma Puzzles

1 May 2017

Posted by on **From New Scientist #2273, 13th January 2001** [link]

Recently I read this exercise in a school book:

“Start with a whole number, reverse it and then add the two together to get a new number. Repeat the process until you have a palindrome. For example, starting with 263 gives:

leading to the palindrome 2662.”

I tried this by starting with a three-figure number. I reversed it to give a larger number, and then I added the two together, but my answer was still not palindromic. So I repeated the process, which gave me another three-figure number which was still not palindromic. In fact I had to repeat the process twice more before I reached a palindrome.

What number did I start with?

[enigma1117]

Advertisements

%d bloggers like this:

This Python program runs in 55ms.

Solution:The starting number was 192.Most 3-digit numbers resolve quite quickly to a palindromic number, but there are a few that take 10 or more applications of the procedure:

The ones marked with a

?never reach a palindromic number.For numbers not ending in 0 the reverse of that number will also behave in the same way (e.g. 928 will also take 10 applications of the procedure before reaching a palindrome).

Jim, I used your ‘nreverse’ function from enigma.py to easily reverse numbers in my programme.

Without the constraint that the second addition must be three digits, the first number is 174

and there are multiple answers.

Output – 2nd addition not restricted to three digits

(174, 471, 645, 1191, 3102, 5115)

(175, 571, 746, 1393, 5324, 9559)

(183, 381, 564, 1029, 10230, 13431)

(192, 291, 483, 867, 1635, 6996) << answer

(195, 591, 786, 1473, 5214, 9339)

(273, 372, 645, 1191, 3102, 5115)

(274, 472, 746, 1393, 5324, 9559)

(294, 492, 786, 1473, 5214, 9339)

etc