Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,10 +1,13 @@
def droot (n):
x = [n]
while x[-1] > 10:
x.append(sum(int(dig) for dig in str(x[-1])))
return len(x) - 1, x[-1]
def digital_root (n):
ap = 0
n = abs(int(n))
while n >= 10:
n = sum(int(digit) for digit in str(n))
ap += 1
return ap, n
for n in [627615, 39390, 588225, 393900588225]:
a, d = droot (n)
print "%12i has additive persistance %2i and digital root of %i" % (
n, a, d)
if __name__ == '__main__':
for n in [627615, 39390, 588225, 393900588225, 55]:
persistance, root = digital_root(n)
print("%12i has additive persistance %2i and digital root %i."
% (n, persistance, root))