Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. In this kata, you must create a digital root function.
  2.  
  3. A 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 two digits, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
  4.  
  5. Here's how it works (Ruby example given):
  6.  
  7. ```
  8. digital_root(16)
  9. => 1 + 6
  10. => 7
  11.  
  12. digital_root(942)
  13. => 9 + 4 + 2
  14. => 15 ...
  15. => 1 + 5
  16. => 6
  17.  
  18. digital_root(132189)
  19. => 1 + 3 + 2 + 1 + 8 + 9
  20. => 24 ...
  21. => 2 + 4
  22. => 6
  23.  
  24. digital_root(493193)
  25. => 4 + 9 + 3 + 1 + 9 + 3
  26. => 29 ...
  27. => 2 + 9
  28. => 11 ...
  29. => 1 + 1
  30. => 2
  31. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement