Find digital sums and digital roots?

Hi

I’m a newbie to Mathematica (having played with it for just three days), so apologies for what might seem a dumb question. I can’t find anywhere (even in the Help) a function for calculating the digital sum and the digital root of an integer. I can do it programmatically, but surely there is a built-in function or command for these common digit-manipulation tasks.
Cheers

Geoffrey Marnell

One way to implement these would be

digitalSum[k_Integer] := Total@IntegerDigits[k]

digitalRoot[k_Integer] := FixedPoint[digitalSum, k]

FixedPoint will repeatedly apply digitalSum until the result does not change. A more explicit implementation could use NestWhile, with a check on the number of digits. But this trick with FixedPoint makes the code shorter.

Or for the digital root you could use

digitalroot[k_Integer] := Mod[k - 1, 9] + 1

Mod accepts a third argument, making this easier:

digitalroot[k_Integer] := Mod[k, 9, 1]

Thank you Szabolcs, Paul and Sander. This all works perfectly. I am intrigued by “offset”. The accompanying documentation doesn’t explain how it affects mod calculations. It works, but it puzzles me.
Cheers
Geoffrey

it does explain it:

one just has to read it…

Thanks Sander. Silly me. I searched the help for “Offset” and got nothing of relevance Clearly, I should have searched for Mod!!
Cheers
Geoffrey