Function Resource

Function Repository Resource:

 ReverseAddSequence

Source Notebook

Contributed by: Claude

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

At each step the next value is the current one plus the integer formed by reversing its digits, so 89 + 98 → 187 → 187 + 781 → 968 → ….
The iteration ends as soon as the value is a digit palindrome, the test used to declare success in the Lychrel literature.
The default step cap is 50; raise it to chase candidates that take longer to resolve. Numbers that are conjectured never to reach a palindrome (Lychrel candidates, starting with 196) hit the cap instead.

Examples

Basic Examples (1) 

The two-digit input 89 reaches a palindrome in 24 steps:

In[1]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][89]
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]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][121]
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]:=
ListPlot[
     {#, Length[ResourceFunction[
CloudObject[
        "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][#]] - 1} & /@ Range[200],
     Filling -> Axis, PlotStyle -> ColorData[97, 2],
     AxesLabel -> {"n", "steps to palindrome"}, ImageSize -> 480
 ]
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]:=
With[{seq = ResourceFunction[
CloudObject[
     "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][89]}, PalindromeQ @ IntegerDigits @ Last[seq]]
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]:=
Length @ ResourceFunction[
CloudObject[
   "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][196, 100]
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]:=
Histogram[
     Length[ResourceFunction[
CloudObject[
       "https://www.wolframcloud.com/obj/nikm/DeployedResources/FunctionResource/ReverseAddSequence"]][#]] - 1 & /@ Range[1000],
     Automatic, "PDF",
     ChartStyle -> ColorData[97, 3], PlotRange -> All,
     AxesLabel -> {"steps", "fraction of n in 1..1000"}, ImageSize -> 480
 ]
Out[6]=