Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- from itertools import product
- from tqdm import tqdm
- @lru_cache(maxsize=None)
- def per(n, base=10):
- if n < base:
- return 0
- new_n = 1
- while n:
- new_n *= n % base
- # remove last digit from number (as integer)
- n //= base
- return 1 + per(new_n, base)
- BASE = 10
- added_digits = [n for n in [2, 3, 5, 7, 11, 13, 17, 19] if n < BASE]
- options = added_digits
- max_found = 0
- f = open("out.txt", "a")
- i = 0
- while True:
- i += 1
- print("------")
- print("So far, we found max", max_found, "persistance")
- print("With", i, "digits")
- print("Number of options", len(options))
- for p in tqdm(options):
- x = per(p, base=BASE)
- if x > max_found:
- print()
- print("Found", x, p)
- f.write("\nFound " + str(x) + " " + str(p))
- max_found = x
- print()
- options = [a * BASE + b for a, b in product(options, added_digits) if a % BASE <= b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement