Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from functools import lru_cache
  2. from itertools import product
  3.  
  4. from tqdm import tqdm
  5.  
  6.  
  7. @lru_cache(maxsize=None)
  8. def per(n, base=10):
  9.     if n < base:
  10.         return 0
  11.  
  12.     new_n = 1
  13.     while n:
  14.         new_n *= n % base
  15.         # remove last digit from number (as integer)
  16.         n //= base
  17.  
  18.     return 1 + per(new_n, base)
  19.  
  20.  
  21. BASE = 10
  22.  
  23. added_digits = [n for n in [2, 3, 5, 7, 11, 13, 17, 19] if n < BASE]
  24. options = added_digits
  25.  
  26. max_found = 0
  27.  
  28. f = open("out.txt", "a")
  29.  
  30. i = 0
  31. while True:
  32.     i += 1
  33.     print("------")
  34.     print("So far, we found max", max_found, "persistance")
  35.     print("With", i, "digits")
  36.     print("Number of options", len(options))
  37.     for p in tqdm(options):
  38.         x = per(p, base=BASE)
  39.         if x > max_found:
  40.             print()
  41.             print("Found", x, p)
  42.             f.write("\nFound " + str(x) + " " + str(p))
  43.  
  44.             max_found = x
  45.     print()
  46.  
  47.     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