The wsq10 asks me to do a program that recieves only two data from the user: a lower bound and an upper bound.

With thopse two parameters I had to tell the user how many palindromes, see for palindromes, are in that range; how many palindromes are in that range after do the Lychrel number test and how many Lycher there exists, see for Lychrel.

The first thing I did was seting the condition needed to get a natural palindrome, like 55 or 101, then to set a condition to exclude base 10 numbers, like 130 o 18290;

Capture

That means, if x and y are the same (if is a palindrome 🙂 ) we’ve got a palindrome; if the last digit is cero, then is a base 10 number and i counted it as a plaindrome.

Then, the hard parts makes its entrance

asdasd

Well, that means that if it is not a natural palindrome, and is not a base ten number, then we will try to convert it to palindrome by adding the number with its inverse, in the code is the part x = x + y, where y = x[::-1].

EXTRA: the code x[::-1] means that it will ignore the start and the end and it just going to move the last digit. The wrong way to do it it’s putting cero

So that loop will check it 30 times, if it does not meet the condition x == y, then it will be a Lychrel number, else it will be a forced palindrome.

It was really a challange to me and I really liked it; i’d like to do more of those challenging programs

Github code

CC BY 4.0 WSQ11: A pain in the … feelings by charliegdrummer is licensed under a Creative Commons Attribution 4.0 International License.