Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Basic algorithm for finding Digital Root #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Basic-Scripts/digital_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
The digital root (also repeated digital sum) of a natural number in
a given number base is the (single digit) value obtained by an iterative
process of summing digits, on each iteration using the result from the previous
iteration to compute a digit sum. The process continues until a single-digit number
is reached. - https://en.wikipedia.org/wiki/Digital_root

> digital_root(52)
// 7
(5 + 2)
"""


def digital_root(n):
return (n - 1) % 9 + 1 if n else 0