Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addition = True
- reverse = False
- data = ''
- name = 'Pi'
- choice = raw_input('Enter constant Choice (Pi, 2Pi, Phi, e, em, A, cat, kl, rt): ')
- if choice.lower().strip() == '2pi':
- name = '2Pi'
- with open('/path/to/2pi_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'phi':
- name = 'Phi'
- with open('/path/to/phi_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'e':
- name = 'e'
- with open('/path/to/e_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'em':
- name = 'Euler-Mascheroni'
- with open('/path/to/em_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'a':
- name = 'A'
- with open('/path/to/A.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'cat':
- name = 'Catalan'
- with open('/path/to/catalan_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'kl':
- name = 'Khinchin-Levy'
- with open('/path/to/khinchin-levy_20m.txt') as the_file: data = the_file.read()
- elif choice.lower().strip() == 'rt':
- name = 'Sqrt2'
- with open('/path/to/sqrt_2.txt') as the_file: data = the_file.read()
- else:
- name = 'Pi'
- with open('/path/to/pi_20m.txt') as the_file: data = the_file.read()
- data = data[:100000]
- target = 1
- while True:
- num_input = raw_input('Enter number to search for: ').strip()
- if num_input.isdigit():
- if int(num_input) > 0:
- target = int(num_input)
- break
- target_len = len(str(target)) + 1
- answer = raw_input('\nPress Enter to do addition. Enter anything to do subtraction.')
- if answer != '':
- addition = False
- target_len = 10
- matches = []
- print('')
- for i in range(0, len(data)):
- for length in range(1, target_len): # Iterate through every section length up to target length
- section = data[i:i + length] # n length chunk of Pi
- end_of = i + length
- add_up = section
- add_up2 = end_of
- if reverse:
- add_up = section[::-1]
- add_up2 = int(str(end_of)[::-1])
- if addition == True:
- if int(add_up) + add_up2 == target:
- if [int(section), end_of] not in matches:
- matches.append([int(section), end_of])
- s_stripped = str(int(section))
- instance = ''
- first_occur = len(data.split(s_stripped, 1)[0] + s_stripped)
- if first_occur == end_of: instance = ' first'
- print(s_stripped + instance + ' appears in ' + name + ' at the end of ' + str(end_of) + ' digits (' + str(int(add_up)) + ' + ' + str(add_up2) + ' = ' + str(target) + ')')
- else:
- if abs(int(add_up) - add_up2) == target:
- a_msg = int(add_up)
- b_msg = int(add_up2)
- if a_msg < b_msg:
- a_msg = int(add_up2)
- b_msg = int(add_up)
- if [int(section), end_of] not in matches:
- matches.append([int(section), end_of])
- s_stripped = str(int(section))
- instance = ''
- first_occur = len(data.split(s_stripped, 1)[0] + s_stripped)
- if first_occur == end_of: instance = ' first'
- 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