![]() |
VOOZH | about |
Lychrel Number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. The process is sometimes called the 196-algorithm, after the most famous number associated with the process.
The first few numbers not known to produce palindromes when applying the 196-algorithm (i.e., a reverse-then-add sequence) are sometimes known as Lychrel numbers.
Examples:
Input : 56 Output : 56 is lychrel : false Explanation : 56 becomes palindromic after one iteration : 56 + 65 = 121 Input : 196 Output : 196 is lychrel : true Explanation : 196 becomes palindromic after 19 iterations : 196 + 691 = 887 887 + 788 = 1675 1675 + 5761 = 7436 7436 + 6347 = 13783 13783 + 38731 = 52514 .... 16403234045 + 54043230461 70446464506 + 60546464407
The task is to find if a given number is Lychrel with a given limit on the number of iterations.
1. Iterate given number of times 1. Add number to it's reverse 2. If the newly formed number is palindrome then return false // Number is not lychrel. 2. return true // Number is lychrel
Following are the steps to solve this problem :
Below is the implementation of the above approach :
295 is lychrel ? true