euler/python/e065.py

22 lines
585 B
Python

from e057 import add_fractions
def next_expansion(previous_numerator, previous_denumerator, value):
if previous_numerator == 0:
return (value, 1)
return add_fractions(previous_denumerator, previous_numerator, value, 1)
def euler_065():
e_sequence = [2] + [n for i in range(2, 1000, 2) for n in (1, i, 1)]
n, d = 0, 1
for i in range(100, 0, -1):
n, d = next_expansion(n, d, e_sequence[i - 1])
s = sum([int(l) for l in str(n)])
return s
if __name__ == "__main__":
print("e065.py: " + str(euler_065()))
assert(euler_065() == 272)