Is there an online calculator in which you can type a number and have it tell you if it could be a Lychrel number or not?

390 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

Here you go:

http://js.do/daveyp225/lychrel

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.