Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created February 15, 2019 15:23
Show Gist options
  • Save venelrene/b0db4565222c819f4a345e5dbaed0f8f to your computer and use it in GitHub Desktop.
Save venelrene/b0db4565222c819f4a345e5dbaed0f8f to your computer and use it in GitHub Desktop.
Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.
######### Refactored #########
def persistence(n):
if n < 10: return 0
multiplier = 1
while(n > 0):
multiplier = (n % 10) * multiplier
n = n // 10
return persistence(multiplier) + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment