The digital root, 



X


{\displaystyle X}

, of a number, 



n


{\displaystyle n}

, is calculated:

 find 



X


{\displaystyle X}

 as the sum of the digits of 



n


{\displaystyle n}


 find a new 



X


{\displaystyle X}

 by summing the digits of 



X


{\displaystyle X}

, repeating until 



X


{\displaystyle X}

 has only one digit.
The additive persistence is the number of summations required to obtain the single digit.

The task is to calculate the additive persistence and the digital root of a number, e.g.:





627615


{\displaystyle 627615}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



9


{\displaystyle 9}

;




39390


{\displaystyle 39390}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



6


{\displaystyle 6}

;




588225


{\displaystyle 588225}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



3


{\displaystyle 3}

;




393900588225


{\displaystyle 393900588225}

 has additive persistence 



2


{\displaystyle 2}

 and digital root of 



9


{\displaystyle 9}

;
The digital root may be calculated in bases other than 10.



See

 Casting out nines for this wiki's use of this procedure.
 Digital root/Multiplicative digital root
 Sum digits of an integer
 Digital root sequence on OEIS
 Additive persistence sequence on OEIS
 Iterated digits squaring


/* REXX *************************************************************** 
* Test digroot                                                          
**********************************************************************/ 
                                                 /*           n r p */  
say right(7           ,12) digroot(7           ) /*           7 7 0 */  
say right(627615      ,12) digroot(627615      ) /*      627615 9 2 */  
say right(39390       ,12) digroot(39390       ) /*       39390 6 2 */  
say right(588225      ,12) digroot(588225      ) /*      588225 3 2 */  
say right(393900588225,12) digroot(393900588225) /*393900588225 9 2 */  
  Exit                                                                  
digroot: Procedure                                                      
/********************************************************************** 
* Compute the digital root and persistence of the given decimal number  
* 25.07.2012 Walter Pachl
**************************** Bottom of Data **************************/ 
Parse Arg n                         /* the number                    */ 
p=0                                 /* persistence                   */ 
Do While length(n)>1                /* more than one digit in n      */ 
  s=0                               /* initialize sum                */ 
  p=p+1                             /* increment persistence         */ 
  Do while n<>''                    /* as long as there are digits   */ 
    Parse Var n c +1 n              /* pick the first one            */ 
    s=s+c                           /* add to the new sum            */ 
    End                                                                 
  n=s                               /* the 'new' number              */ 
  End                                                                   
return n p                          /* return root and persistence   */