Wolfram Research

Function Repository Resource:

AdditivePersistence (1.0.0) current version: 1.1.0 »

Source Notebook

Compute the additive persistence of an integer

Contributed by: Christopher Stover

ResourceFunction["AdditivePersistence"][n]

returns the additive persistence of n.

Details

Starting with a non-negative integer n, add its digits, then add the digits of the resulting number, etc., until the result has only one digit. The number of additions required to reach the single digit stopping point is called the additive persistence of n.
As an example, consider n=1191:
Adding its digits yields 1+1+9+1=12.
Adding the digits of the result yields 1+2=3. Because 3 is a single-digit number, the process stops.
Because it took two steps to reach the stopping point, ResourceFunction["AdditivePersistence"][1191] returns 2.
ResourceFunction["AdditivePersistence"] threads elementwise over lists.

Examples

Basic Examples (1) 

Find the additive persistence of 1191:

In[1]:=
ResourceFunction["AdditivePersistence"][1191]
Out[1]=

Scope (2) 

AdditivePersistence threads elementwise over lists:

In[2]:=
ResourceFunction["AdditivePersistence", ResourceVersion->"1.0.0"][{1234, 54321, 66677, 8989109898}]
Out[2]=

Compute the additive persistence of the first 100 integers (OEIS A031286):

In[3]:=
ResourceFunction["AdditivePersistence"] /@ Range[0, 99, 1]
Out[3]=

Properties and Relations (4) 

The result returned by AdditivePersistence can be manually computed using Length with NestWhileList:

In[4]:=
With[{n = 8675309}, ResourceFunction["AdditivePersistence"][n] == Length[NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= 10 &]] - 1]
Out[4]=

The additive persistence of an integer can also be manually computed with no high-level functions:

In[5]:=
testint1 = 1234
Out[5]=
In[6]:=
digits1 = IntegerDigits[testint1]
Out[6]=
In[7]:=
testint2 = Plus @@ digits1
Out[7]=
In[8]:=
digits2 = IntegerDigits[testint2]
Out[8]=
In[9]:=
testint3 = Plus @@ digits2
Out[9]=

Because testint3 is a single-digit integer, the process terminates here. Since it took two steps to reach testint3, the additive persistence of testint1=1234 is equal to 2:

In[10]:=
ResourceFunction["AdditivePersistence"][testint1]
Out[10]=

The single-digit integer that marks the end of the digit addition process is called the additive digital root and is returned by the resource function AdditiveDigitalRoot:

In[11]:=
n = 13579
Out[11]=
In[12]:=
list = NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= 10 &]
Out[12]=
In[13]:=
ResourceFunction["AdditivePersistence"][n] == Length[list] - 1
Out[13]=
In[14]:=
ResourceFunction["AdditiveDigitalRoot"][n] == list[[-1]]
Out[14]=

The multiplicative analogue of additive persistence is called multiplicative persistence and is returned by the resource function MultiplicativePersistence:

In[15]:=
n2 = 2111971
Out[15]=
In[16]:=
{add, mult} = Function[f, NestWhileList[f @@ IntegerDigits[#] &, n2, # >= 10 &]] /@ {Plus, Times}
Out[16]=
In[17]:=
ResourceFunction["AdditivePersistence"][n2] == Length[add] - 1
Out[17]=
In[18]:=
ResourceFunction["MultiplicativePersistence"][n2] == Length[mult] - 1
Out[18]=

Possible Issues (1) 

AdditivePersistence requires its input to be non-negative:

In[19]:=
ResourceFunction["AdditivePersistence"][-234545]
Out[19]=

Neat Examples (1) 

The smallest integers with additive persistence equal to 0,1,2,3,4, (OEIS A006050):

In[20]:=
ResourceFunction["AdditivePersistence", ResourceVersion->"1.0.0"][{0, 10, 19, 199, 19999999999999999999999}]
Out[20]=

The smallest integer with additive persistence 5 is known to equal 1 followed by 2222222222222222222222 9’s.

Publisher

therealcstover

Version History

  • 1.1.0 – 25 May 2023
  • 1.0.0 – 09 August 2022

Related Resources

Author Notes

Future versions of this will likely contain expansion to allow for integers in bases other than 10.

License Information