Palindromic Numbers

Difficulty: ★ ★ ★ ☆

I think most kids delight at discovering the palindrome, where a word or phrase contains the same letters read forward or backwards. For example, racecar, which is really two words but never mind! Imagine how such fun can be spoiled by applying the same rule to a number.

A palindromic number is one that’s decimal representation reads the same forward as backwards. For example, 123321. Unlike cyclops numbers (from last month’s Exercise), these values need not have an odd number of digits. In fact, the first nine numbers are all considered palindromic, though the same rule doesn’t apply to written palindromes (probably because it requires little effort).

Anyhoo, your task for this month’s Exercise is to output the first 100 palindromic numbers, starting with (disappointingly) one. Your solution must devise a method to ensure that the digits on one side of the value match those on the other side. This condition is present for values with odd and even digits, so have fun with that part.

Figure 1 shows the output from my solution.

screen output

Figure 1. Output from my solution, using a table borrowed from last month’s solution.

Ensure that you don’t just code the output text as your solution! No, you have to do programming and calculations and stuff, as I did. Please try this exercise on your own before you view my solution.

Leave a Reply