-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital_roots.py
68 lines (60 loc) · 1.96 KB
/
digital_roots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'''
File: digital_roots.py
Author: Ben Ballard
Description: A python module that provides functions from calculating additive digital roots and multiplicative digital roots
'''
if __name__ != "__main__":
def additive_digitalroot(string):
if len(string) == 1:
return string
total = 0
for i in string:
total += int(i)
new_str = str(total)
print(string + " (" + makeAdditionString(string) + ") -> " + new_str)
return additive_digitalroot(new_str)
def makeAdditionString(string):
equation = ""
for i in string:
equation += i + " + "
return equation[0:len(equation)-3]
def multiplicative_digitalroot(string):
if len(string) == 1:
return string
total = int(string[0:1])
s = string[1:len(string)]
for i in s:
total *= int(i)
new_str = str(total)
print(string + " (" + makeProductString(string) + ") -> " + new_str)
return multiplicative_digitalroot(new_str)
def makeProductString(string):
equation = ""
for i in string:
equation += i + " * "
return equation[0:len(equation)-3]
def subtractive_digitalroot(string):
if len(string) == 1:
return string
total = 0
negative = False
for i in string:
if i == "-":
negative = True
continue
if negative:
total -= -int(i)
negative = False
else:
total -= int(i)
new_str = str(total)
print(string + " (" + makeSubtractString(string) + ") -> " + new_str)
return subtractive_digitalroot(new_str)
def makeSubtractString(string):
equation = ""
for i in string:
if i != "-":
equation += i + " - "
else:
equation += i
return equation[0:len(equation)-3]