/* Function that returns a list of digits given a nonnegative integer */ decompose(num) := block([digits, remainder], digits: [], while num > 0 do (remainder: mod(num, 10), digits: cons(remainder, digits), num: floor(num/10)), digits )$ /* Function that given a positive integer returns the sum of their digits */ auxdig(n):=block(decompose(n),apply("+",%%)); /* Function that given a positive integer returns a list of two: the additive persistence and the digital root */ digrt(n):=block([additive_persistence:0,digital_root:n], while length(decompose(digital_root))>1 do (digital_root:auxdig(digital_root),additive_persistence:additive_persistence+1), [additive_persistence,digital_root]); /* Examples */ digrt(627615); digrt(39390); digrt(588225); digrt(393900588225);