-
-
Save anthonymorast/eb18bb3aeee60fe9eeb5be190e665dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy as np | |
from multiprocessing import Pool | |
import time | |
if __name__=='__main__': | |
if len(sys.argv) < 3: | |
print("Filename and order are required: python3 number_check.py <order> <file>") | |
exit() | |
start = time.time() | |
order = int(sys.argv[1]) | |
filename = sys.argv[2] | |
with open(filename) as f: | |
length = order**2 | |
lines = f.readlines() | |
totals = {} | |
count = 1 | |
for line in lines: # iterate each square in the file | |
if count % 100000 == 0: | |
print(f"Processed {count} out of {len(lines) + 1}.") | |
tot = 0 | |
s = 0 | |
col = 1 | |
row = 1 | |
for i in line: # apply the LS -> number mapping | |
if i == '\n': | |
continue | |
col += 1 | |
s += (int(i) + 1)**(col + row) | |
if col == (order + 1): | |
col = 1 | |
row += 1 | |
tot += np.log(s) | |
s = 0 | |
if tot not in totals.values(): # check if this number has been generated before | |
totals[line] = tot # if not, add it to the dictionary | |
else: | |
other = None # otherwise, determine why the value was the same | |
for t in totals: | |
if totals[t] == tot: | |
other = t | |
break | |
print(f"\t{tot}\n\t{line}\n\t{other}\n\t{totals[other]}") | |
count += 1 | |
end = time.time() | |
# print the results | |
print(f"# Distinct Totals: {len(totals)}\n# Squares: {len(lines)}\nAll Distinct? {len(totals) == len(lines)}\nMax: {max(totals.values())}\ | |
\nTime Taken: {(end - start):.6f} sec/{((end-start)/60):.6f} min") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment