Archive
Archive for June, 2023
Sum the digits of a number until you get just one digit
June 7, 2023
Leave a comment
Problem
Take a positive integer and sum its digits. Repeat this process until you get just one digit.
Example: 1472 🠖 1+4+7+2 = 14 🠖 1+4 = 5. The answer is 5.
Solution
# Python code
n = 1472
result = ((n-1) % 9) + 1
Credits
Thanks to my friend Mocsa who told me this math trick.
