FunctionRacerProblemsRace

Digital Root

BeginnerMathPython, JavaScript, TypeScript, Java, C++

Repeatedly replace num with the sum of its decimal digits until only one digit is left, then return that digit.

For example, 38 becomes 3 + 8 = 11, which becomes 1 + 1 = 2.

Example 1

num 38
returns 2

38 -> 11 -> 2.

Example 2

num 7
returns 7

Already one digit.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems