From 0c04dfb05980d87ff5fac1a9a3ffd1f3084caea2 Mon Sep 17 00:00:00 2001 From: TheRealDarkCoder Date: Fri, 2 Oct 2020 18:29:57 +0600 Subject: [PATCH] Basic algorithm for finding Digital Root --- Basic-Scripts/digital_root.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Basic-Scripts/digital_root.py diff --git a/Basic-Scripts/digital_root.py b/Basic-Scripts/digital_root.py new file mode 100644 index 00000000..347b072e --- /dev/null +++ b/Basic-Scripts/digital_root.py @@ -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