An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
July 2, 2020 02:11 pm GMT
Original Link: https://dev.to/thepracticaldev/daily-challenge-264-digital-root-44fm
Daily Challenge 264 - Digital Root
Digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
Examples
16 --> 1 + 6 = 7942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2
Tests
digital_root(456)
digital_root(16)
Good luck!
This challenge comes from user578387 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!
Original Link: https://dev.to/thepracticaldev/daily-challenge-264-digital-root-44fm
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To