Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addition = True
- 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
- answer = raw_input('\nPress Enter to do addition. Enter anything to do subtraction.')
- if answer != '': addition = False
- matches = []
- print('')
- for i in range(0, len(data)):
- for length in range(2, 15):
- section = data[i:i + length]
- end_of = i + length
- for j in range(1, len(section)):
- a_s = section[:j]
- b_s = section[j:]
- a = int(a_s)
- b = int(b_s)
- if addition == True:
- if a + b == target:
- if end_of not in matches:
- matches.append(end_of)
- print('"' + a_s + ' ' + b_s + '" occurs at the end of ' + str(end_of) + ' digits of ' + name + ' (' + str(a) + ' + ' + str(b) + ' = ' + str(target) + ')')
- else:
- if abs(a - b) == target:
- a_msg = str(a)
- b_msg = str(b)
- if a < b:
- a_msg = str(b)
- b_msg = str(a)
- if end_of not in matches:
- matches.append(end_of)
- print('"' + a_s + ' ' + b_s + '" occurs at the end of ' + str(end_of) + ' digits of ' + name + ' (' + a_msg + ' - ' + b_msg + ' = ' + str(target) + ')')
Advertisement
Add Comment
Please, Sign In to add comment