Skip to content

Instantly share code, notes, and snippets.

@eli2and40
Created August 3, 2020 14:37
Show Gist options
  • Save eli2and40/7521adf71194118e9910236bf54155ec to your computer and use it in GitHub Desktop.
Save eli2and40/7521adf71194118e9910236bf54155ec to your computer and use it in GitHub Desktop.
def mulPer(n):
"""Computes the Multiplicative Persistence of an int or float in base-10 positional notation
Dependencies: pipe (from meta)
In: Integer
Out: Integer"""
# Exclusions
if n == 0:
return 0
elif len(str(n)) == 1:
return 0
elif (len(str(n)) == 2) and (str(1) in str(n)):
return 1
elif (str(0) in str(n)):
return 1
else:
cache = []
while len(str(n)) > 1:
digitList = [int(i) for i in "".join(str(n).split('.'))]
n = pipe(digitList)
cache.append(n)
return len(cache)
def addPer(n):
"""Computes the Additive Persistence of an int or float in base-10 positional notation
Dependencies: sigma (from meta)
In: Integer
Out: Integer"""
if len(str(n)) == 1:
return 0
elif len(str(n)) < 1:
return ValueError("Your number of choice has less than one digit")
else:
cache = []
while len(str(n)) > 1:
digitList = [int(i) for i in "".join(str(n).split('.'))]
n = sigma(digitList)
cache.append(n)
return len(cache)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment