Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from functools import reduce as rd
- # a comment on https://youtu.be/Wim9WJeDTHQ
- def mul(a: int, b: int) -> int:
- return a * b
- digits = lambda _t: (int(_i) for _i in str(_t))
- def multiplicative_persistence(x: int, show: bool = True) -> int:
- tmp: int = x
- count: int = 1
- while True:
- tmp_exp: [int] = tuple(digits(tmp))
- if show:
- print(f'#{count} is {tmp} (length {len(tmp_exp)})')
- if len(tmp_exp) == 1:
- break
- try:
- tmp = rd(mul, tmp_exp)
- except OverflowError:
- if show:
- print('Crash')
- break
- else:
- raise
- count += 1
- return count
- mp = multiplicative_persistence
- def dsum(_d: [int]) -> int:
- l: int = len(_d) - 1
- return sum(v * 10 ** (l - i) for i, v in enumerate(_d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement