Digit Sum (Repeatedly Until Single Digit)
E · easyP · Verified PYQmath
Problem
Given a number N, repeatedly sum its digits until you get a single digit. Print that digit. Example: 9875 → 9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2
Example
Input
9875
Output
2
Digital root formula: 1 + (n-1)%9 for n>0. Or loop: while n>=10: n = sum of digits.