Digital root (source code)

= Digital root
{title2=$\operatorname{dr}_b(n)$}

Repeatedly sum the <numerical digits> of a <nonnegative integer> in base $b$ until a single <numerical digit> remains. For $n>0$, the result is $1+((n-1)\bmod(b-1))$, while the result for zero is zero. This follows because $b\equiv1\pmod{b-1}$, so summing <numerical digits> preserves the <integer congruence> class <modulo> $b-1$.