Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Copyright (c) 2023 Zeromega
- Drop a link or a Sub on one of my videos if this script help you, copy the link below
- https://www.youtube.com/channel/UCfqUJ4rmk6W-ZAjDtkBZ1CA?sub_confirmation=1
- """
- from mpmath import mp
- import threading
- def find_target_sequence(sequence, target, start, end, result):
- for i in range(start, end - len(target) + 1):
- if sequence[i:i + len(target)] == target:
- result.append((i + 1, i + len(target)))
- print(f"Thread-{threading.get_ident()}: Target sequence found at position {i + 1} to {i + len(target)}: {sequence[i:i + len(target)]}")
- break
- def find_consecutive_sequence(sequence, target, start, end, result):
- consecutive_count = 1
- for i in range(start + 1, end):
- if sequence[i] == sequence[i - 1]:
- consecutive_count += 1
- if consecutive_count == len(target):
- result.append((i - len(target) + 2, i + 1))
- print(f"Thread-{threading.get_ident()}: Consecutive sequence of length {len(target)} found at position {i - len(target) + 2} to {i + 1}: {sequence[i - len(target) + 1:i + 1]}")
- break
- else:
- consecutive_count = 1
- precision = 10000000
- target_sequence = "9999999"
- search_range = 1000000
- mp.dps = precision
- pi = mp.pi
- pi_str = str(pi)
- target_positions = []
- consecutive_positions = []
- num_threads = 4
- target_threads = []
- chunk_size = len(pi_str) // num_threads
- for i in range(num_threads):
- start = i * chunk_size
- end = start + chunk_size
- thread = threading.Thread(target=find_target_sequence, args=(pi_str, target_sequence, start, end, target_positions))
- target_threads.append(thread)
- thread.start()
- print(f"Main thread: Target sequence search started using {num_threads} threads.")
- for thread in target_threads:
- thread.join()
- print("Main thread: Target sequence search completed.")
- consecutive_threads = []
- chunk_size = search_range // num_threads
- for i in range(num_threads):
- start = i * chunk_size
- end = start + chunk_size
- thread = threading.Thread(target=find_consecutive_sequence, args=(pi_str, target_sequence, start, end, consecutive_positions))
- consecutive_threads.append(thread)
- thread.start()
- print(f"Main thread: Consecutive sequence search started using {num_threads} threads.")
- for thread in consecutive_threads:
- thread.join()
- print("Main thread: Consecutive sequence search completed.")
- print("Target sequences found:")
- for start, end in target_positions:
- print(f"Position {start} to {end}: {pi_str[start - 1:end]}")
- print("Consecutive sequences found:")
- for start, end in consecutive_positions:
- print(f"Position {start} to {end}: {pi_str[start - 1:end]}")
- if not target_positions:
- print("No target sequences found.")
- if not consecutive_positions:
- print("No consecutive sequences found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement