Work on problem 99 but struggling more than I should
parent
7efb4fb78f
commit
6af234724d
|
@ -1,24 +1,43 @@
|
|||
from collections import namedtuple
|
||||
|
||||
|
||||
# def lower_upper_bound(a, b):
|
||||
# print(a, b)
|
||||
# return 0
|
||||
Exp = namedtuple("Exp", ["b", "p"])
|
||||
|
||||
|
||||
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():
|
||||
with open("../txt/EulerProblem099.txt", "r") as f:
|
||||
pairs = [(int(s[0]), int(s[1]), i)
|
||||
for i, line in enumerate(f.readlines())
|
||||
if (s := line.split(","))]
|
||||
pairs = read_exps()
|
||||
#a = Exp(2, 350)
|
||||
#b = Exp(5, 150)
|
||||
|
||||
# pairs.sort()
|
||||
|
||||
print(pairs[:2])
|
||||
i = 19
|
||||
a, b = pairs[i:i + 2]
|
||||
print(a, b)
|
||||
a, b = compare_exp(a, b)
|
||||
print(a, b)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_099()
|
||||
print("e099.py: " + str(solution))
|
||||
assert(solution == 0)
|
||||
# assert(solution == 0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue