Work on problem 99 but struggling more than I should

main
Felix Martin 2021-04-21 22:08:47 -04:00
parent 7efb4fb78f
commit 6af234724d
1 changed files with 31 additions and 12 deletions

View File

@ -1,24 +1,43 @@
from collections import namedtuple
# def lower_upper_bound(a, b): Exp = namedtuple("Exp", ["b", "p"])
# print(a, b)
# return 0
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def compare_exp(a, b):
g = gcd(a.p, b.p)
print(g)
return (Exp(a.b, a.p // g), Exp(b.b, b.p // g))
def read_exps():
with open("../txt/EulerProblem099.txt", "r") as f:
return [Exp(int(s[0]), int(s[1]))
for i, line in enumerate(f.readlines())
if (s := line.split(","))]
def euler_099(): def euler_099():
with open("../txt/EulerProblem099.txt", "r") as f: pairs = read_exps()
pairs = [(int(s[0]), int(s[1]), i) #a = Exp(2, 350)
for i, line in enumerate(f.readlines()) #b = Exp(5, 150)
if (s := line.split(","))]
# pairs.sort() i = 19
a, b = pairs[i:i + 2]
print(pairs[:2]) print(a, b)
a, b = compare_exp(a, b)
print(a, b)
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
solution = euler_099() solution = euler_099()
print("e099.py: " + str(solution)) print("e099.py: " + str(solution))
assert(solution == 0) # assert(solution == 0)