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


$ include "seed7_05.s7i";
  include "bigint.s7i";
 
const func bigInteger: digitalRoot (in var bigInteger: num, in bigInteger: base, inout bigInteger: persistence) is func
  result
     var bigInteger: sum is 0_;
  begin
    persistence := 0_;
    while num >= base do
      sum := 0_;
      while num > 0_ do
        sum +:= num rem base;
        num := num div base;
      end while;
      num := sum;
      incr(persistence);
    end while;
  end func;
 
const proc: main is func
  local
    var bigInteger: num is 0_;
    var bigInteger: root is 0_;
    var bigInteger: persistence is 0_;
  begin
    for num range [] (627615_, 39390_, 588225_, 393900588225_) do
      root := digitalRoot(num, 10_, persistence);
      writeln(num <& " has additive persistence " <& persistence <& " and digital root of " <& root);
    end for;
  end func;