Skip to content

Instantly share code, notes, and snippets.

@ayamdobhal
Created April 7, 2020 06:25
Show Gist options
  • Save ayamdobhal/a0928cb337705817b8aa73fd8719992b to your computer and use it in GitHub Desktop.
Save ayamdobhal/a0928cb337705817b8aa73fd8719992b to your computer and use it in GitHub Desktop.
def persistance(N, steps=0):
if len(str(N)) > 1:
steps += 1
digits = [int(x) for x in str(N)]
result = 1
for i in digits:
result *= i
steps = persistance(result, steps)
return steps
n = int(input('Enter the multiplicative persistance: '))
MP = 0
count = 0
while True:
count += 1
MP = persistance(count)
if MP == n:
print('Smallest number with persistance of', n, 'is', count)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment