An Interest In:
Web News this Week
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
- February 27, 2024
- February 26, 2024
July 9, 2021 08:59 am GMT
Original Link: https://dev.to/princebillygk/digital-root-5dpj
(Digital Root)
173 :
1 + 7 + 3 = 11
1 + 1 = 2
2
9256987
9 + 2 + 5 + 6 + 9 + 9 + 7 = 46
4 + 6 = 10
1 + 0 = 1
1
Naive method ( )
DigitalRoot(1) = 1
DigitalRoot(2) = 2
DigitalRoot(3) = 3
... ... ...
DigtalRoot(9) = 9
DigitalRoot(10) =1 + 0 -> 1
DigtalRoot(11) = 1 + 1 -> 2
DigitalRoot(12) = 1 + 2 -> 3
DigitalRoot(13) = 1 + 3 = 4
... ... ...
DigitalRoot(18) = 1 + 8 = 9
... ... ...
digital root , , , , , , , ,
1 mod 9 = 1
2 mod 2 = 2
...
9 mod 9 = 0 ( )
10 mod 9 = 1
11 mod 9 = 2
12 mod 9 = 3
13 mod 9 = 4
...
18 mod 9 = 0 (9)
... ... ...
Python code snippet:
def dr(n): if n == 0: return 0 m = n % 9 return m if m != 0 else 9
Big(o) Complexity: O(1)
Original Link: https://dev.to/princebillygk/digital-root-5dpj
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