Solve problem 99... yes I definitely should not have struggled that hard
parent
6af234724d
commit
194393cae3
|
@ -1,43 +1,25 @@
|
|||
from collections import namedtuple
|
||||
import math
|
||||
|
||||
|
||||
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 exp_log(base, power):
|
||||
return power * math.log(base)
|
||||
|
||||
|
||||
def read_exps():
|
||||
with open("../txt/EulerProblem099.txt", "r") as f:
|
||||
return [Exp(int(s[0]), int(s[1]))
|
||||
return [(exp_log(int(s[0]), int(s[1])), i + 1)
|
||||
for i, line in enumerate(f.readlines())
|
||||
if (s := line.split(","))]
|
||||
|
||||
|
||||
def euler_099():
|
||||
pairs = read_exps()
|
||||
#a = Exp(2, 350)
|
||||
#b = Exp(5, 150)
|
||||
|
||||
i = 19
|
||||
a, b = pairs[i:i + 2]
|
||||
print(a, b)
|
||||
a, b = compare_exp(a, b)
|
||||
print(a, b)
|
||||
return 0
|
||||
exps = read_exps()
|
||||
exps.sort()
|
||||
return exps[-1][1]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_099()
|
||||
print("e099.py: " + str(solution))
|
||||
# assert(solution == 0)
|
||||
assert(solution == 709)
|
||||
|
||||
|
|
Loading…
Reference in New Issue