Function Repository Resource:
ReverseAdd Sequence
ResourceFunction["ReverseAddSequence"][n] gives the trajectory of the reverse-and-add iteration starting from the integer 𝑛, stopping at the first palindromic value. | |
ResourceFunction["ReverseAddSequence"][n, max] stops after at most 𝑚𝑎𝑥 iterations even if no palindrome was reached. |
Details and Options
Examples
Basic Examples (1) 
The two-digit input 89 reaches a palindrome in 24 steps:
| In[1]:= |
| Out[1]= |
Scope (1) 
PalindromeQ is used on the digit list, so any nonnegative integer is accepted, including ones that are already palindromic:
| In[2]:= |
| Out[2]= |
Applications (1) 
How many steps does each starting value need before it becomes palindromic? The plot shows the strikingly uneven landscape that the Lychrel problem is about:
| In[3]:= |
| Out[3]= |
Properties and Relations (1) 
The trajectory is exactly the NestWhileList of # + IntegerReverse[#] & under the palindrome test, so the final value is always palindromic when the sequence terminates:
| In[4]:= |
| Out[4]= |
Possible Issues (1) 
196 is the smallest candidate Lychrel number: no palindrome has ever been found for it. The function returns once the step cap is reached, with a trajectory that just keeps growing:
| In[5]:= |
| Out[5]= |
Neat Examples (1) 
Map the steps-to-palindrome over the first thousand integers, then bucket by that count: most resolve quickly, but a thin tail of starting values needs dozens of iterations before the digits line up:
| In[6]:= |
| Out[6]= |