Advertisement
Guest User

42, 93, 135 Test

a guest
Jan 3rd, 2021
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. addition = True
  2. reverse = False
  3.  
  4. data = ''
  5. name = 'Pi'
  6.  
  7. choice = raw_input('Enter constant Choice (Pi, 2Pi, Phi, e, em, A, cat, kl, rt): ')
  8.  
  9. if choice.lower().strip() == '2pi':
  10.     name = '2Pi'
  11.     with open('/path/to/2pi_20m.txt') as the_file: data = the_file.read()
  12. elif choice.lower().strip() == 'phi':
  13.     name = 'Phi'
  14.     with open('/path/to/phi_20m.txt') as the_file: data = the_file.read()
  15. elif choice.lower().strip() == 'e':
  16.     name = 'e'
  17.     with open('/path/to/e_20m.txt') as the_file: data = the_file.read()
  18. elif choice.lower().strip() == 'em':
  19.     name = 'Euler-Mascheroni'
  20.     with open('/path/to/em_20m.txt') as the_file: data = the_file.read()
  21. elif choice.lower().strip() == 'a':
  22.     name = 'A'
  23.     with open('/path/to/A.txt') as the_file: data = the_file.read()
  24. elif choice.lower().strip() == 'cat':
  25.     name = 'Catalan'
  26.     with open('/path/to/catalan_20m.txt') as the_file: data = the_file.read()
  27. elif choice.lower().strip() == 'kl':
  28.     name = 'Khinchin-Levy'
  29.     with open('/path/to/khinchin-levy_20m.txt') as the_file: data = the_file.read()
  30. elif choice.lower().strip() == 'rt':
  31.     name = 'Sqrt2'
  32.     with open('/path/to/sqrt_2.txt') as the_file: data = the_file.read()
  33. else:
  34.     name = 'Pi'
  35.     with open('/path/to/pi_20m.txt') as the_file: data = the_file.read()
  36.  
  37. data = data[:100000]
  38.  
  39. target = 1
  40.  
  41. while True:
  42.     num_input = raw_input('Enter number to search for: ').strip()
  43.     if num_input.isdigit():
  44.         if int(num_input) > 0:
  45.             target = int(num_input)
  46.             break
  47.  
  48. target_len = len(str(target)) + 1
  49.  
  50. answer = raw_input('\nPress Enter to do addition. Enter anything to do subtraction.')
  51.  
  52. if answer != '':
  53.     addition = False
  54.     target_len = 10
  55.  
  56. matches = []
  57.  
  58. print('')
  59.  
  60. for i in range(0, len(data)):
  61.     for length in range(1, target_len):     # Iterate through every section length up to target length
  62.         section = data[i:i + length]                        # n length chunk of Pi
  63.         end_of = i + length
  64.  
  65.         add_up = section
  66.         add_up2 = end_of
  67.  
  68.         if reverse:
  69.             add_up = section[::-1]
  70.             add_up2 = int(str(end_of)[::-1])
  71.  
  72.         if addition == True:
  73.             if int(add_up) + add_up2 == target:
  74.                 if [int(section), end_of] not in matches:
  75.                     matches.append([int(section), end_of])
  76.  
  77.                     s_stripped = str(int(section))
  78.  
  79.                     instance = ''
  80.                     first_occur = len(data.split(s_stripped, 1)[0] + s_stripped)
  81.  
  82.                     if first_occur == end_of: instance = ' first'
  83.  
  84.                     print(s_stripped + instance + ' appears in ' + name + ' at the end of ' + str(end_of) + ' digits (' + str(int(add_up)) + ' + ' + str(add_up2) + ' = ' + str(target) + ')')
  85.         else:
  86.             if abs(int(add_up) - add_up2) == target:
  87.  
  88.                 a_msg = int(add_up)
  89.                 b_msg = int(add_up2)
  90.  
  91.                 if a_msg < b_msg:
  92.                     a_msg = int(add_up2)
  93.                     b_msg = int(add_up)
  94.  
  95.                 if [int(section), end_of] not in matches:
  96.                     matches.append([int(section), end_of])
  97.  
  98.                     s_stripped = str(int(section))
  99.  
  100.                     instance = ''
  101.                     first_occur = len(data.split(s_stripped, 1)[0] + s_stripped)
  102.  
  103.                     if first_occur == end_of: instance = ' first'
  104.  
  105.                     print(s_stripped + instance + ' appears in ' + name + ' at the end of ' + str(end_of) + ' digits (' + str(a_msg) + ' - ' + str(b_msg) + ' = ' + str(target) + ')')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement