Skip to content

Commit

Permalink
Cleanup of initial checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nexxai committed Nov 11, 2021
1 parent b32cd78 commit 1834418
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions friendly.py
Expand Up @@ -17,7 +17,7 @@
import sys, os, re

# SETTINGS
index_search = 10 # Get the index of '10'
friendly_number = 10 # The integer we want to find friendly numbers for
where_to_start = 10**12 # 1 trillion
where_to_end = 10**13 # 10 trillion (e.g. search from 1 trillion to 10 trillion)
checkpoint = 10**4 # Update the checkpoint after how many checks?
Expand All @@ -27,32 +27,32 @@
if os.path.isfile(progress_file_name):
# If so, open it...
progress_file = open(progress_file_name, "r")
if progress_file.mode == 'r':
# and get the current checkpoint
start_num = progress_file.read()
# If it contains the text 'FOUND' just print it out and exit
match = re.search(r"FOUND:\s(\d{1,})", start_num)
if match:
print(start_num)
print(divisors(int(match.group(1))))
sys.exit()
# Otherwise we're loading in that checkpoint
start_num = int(start_num)

# and get the current checkpoint
last_checked = progress_file.read()

# If it contains the text 'FOUND' just print it out and exit
match = re.search(r"FOUND:\s(\d{1,})", last_checked)
if match:
print(last_checked)
print(divisors(int(match.group(1))))
sys.exit()
# Otherwise it's just a number and we're starting from that point
start_num = int(last_checked)
else:
# No progress file found, so just start at the beginning
start_num = where_to_start

# Find the index of the provided integer
# (The [0] is because find_index returns 3 values, we only want the first)
search = find_index(index_search)[0]
search = find_index(friendly_number)[0]

# Just start looping through each number, one by one
for num in range(start_num, where_to_end):
# Destructure find_index into its appropriate variables
index, sum_of_factors, factors = find_index(num)

# If it matches index_search, we found one so break out of the loop
# If it matches friendly_number, we found one so break out of the loop
if index == search:
print(f'{sum_of_factors} / {num} = {index}')
print(factors)
Expand Down

0 comments on commit 1834418

Please sign in to comment.