Created
February 15, 2019 15:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######### 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