Say you type $7326$ into it, it runs a few calculations and tells you it reaches $99099$ in three iterations. But if you type in a number like $887$, it runs a reasonable number of iterations (say, twenty) and tells you it doesn't reach a palindrome in that number of iterations.

In response to another question, I tried to determine if $9988$ is a Lychrel number. After ten iterations on a general purpose calculator, I could not find a palindrome, but I could have made a mistake somewhere. I also tried asking Google "Is $9988$ a Lychrel number?" The results were unenlightening.

  • 2
    $\begingroup$ It's unknown, as well as all the other terms in oeis.org/A023108 and many more. $\endgroup$ Dec 21, 2014 at 3:01
  • $\begingroup$ But surely there is some tool that can reliably tell me that it doesn't reach a palindrome in some small number of iterations, some tool that's not going to inadvertently mix up the digits (e.g., type 68779 instead of 86779). $\endgroup$ Dec 21, 2014 at 3:14
  • 2
    $\begingroup$ One can write a short program to do this in any high-level language, e.g. Python. $\endgroup$
    – vadim123
    Dec 21, 2014 at 3:15
  • $\begingroup$ If I really wanted to, I could do it in Javascript. But wouldn't I be reinventing the wheel? Hasn't anyone done this and made it available online? $\endgroup$ Dec 21, 2014 at 3:18
  • 2
    $\begingroup$ @vadim123 See Code Review question 44272 for a Python implementation. $\endgroup$ Dec 28, 2014 at 2:34

1 Answer 1


Here you go:


I tried to make the code semi-readable, just set $N$ to the number of iterations you wish to go before rejecting; by default I have it set to $25$. The value of the iterations rises very quickly. As a result, too high of iterations are not supported by javascript. Without a moderate amount of additional work (e.g. custom classes) this is roughly the best javascript can do. If there are any obvious improvements I can make let me know.

Edit: I had to make a correction, as for some reason a few select powers of ten do not behave well with javascript. For example:

Math.log(1000)/Math.log(10) Returns 2.9999999999999996 rather than 3.

This correction will not affect any "ordinary" inputs. I added $10^{-14}$ to the logarithm before taking the floor of the input.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .