Advertisement
zeromega64twenty

PI Recursive Number Finder

Aug 27th, 2023 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | Source Code | 0 0
  1. """
  2. Copyright (c) 2023 Zeromega
  3. Drop a link or a Sub on one of my videos if this script help you, copy the link below
  4. https://www.youtube.com/channel/UCfqUJ4rmk6W-ZAjDtkBZ1CA?sub_confirmation=1
  5. """
  6.  
  7. from mpmath import mp
  8.  
  9. precision = 10000000
  10. target_sequence = "9999999"
  11. search_range = 1000000
  12. mp.dps = precision
  13. pi = mp.pi
  14.  
  15. pi_str = str(pi)
  16.  
  17. for i in range(len(pi_str) - len(target_sequence) + 1):
  18.     if pi_str[i:i + len(target_sequence)] == target_sequence:
  19.         print(f"Target sequence found at position {i + 1} to {i + len(target_sequence)}: {pi_str[i:i + len(target_sequence)]}")
  20.         break
  21.  
  22. consecutive_found = False
  23. consecutive_count = 1
  24.  
  25. for i in range(1, search_range):
  26.     if pi_str[i] == pi_str[i - 1]:
  27.         consecutive_count += 1
  28.         if consecutive_count == len(target_sequence):
  29.             consecutive_found = True
  30.             print(f"Consecutive sequence of length {len(target_sequence)} found at position {i - len(target_sequence) + 2} to {i + 1}: {pi_str[i - len(target_sequence) + 1:i + 1]}")
  31.             break
  32.     else:
  33.         consecutive_count = 1
  34.     print(f"Searching at position {i + 1}...")
  35.  
  36. if not consecutive_found:
  37.     print("No consecutive sequence found.")
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement