2019-07-18 20:23:44 +02:00
|
|
|
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)
|
|
|
|
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
def euler_065():
|
2019-07-18 20:23:44 +02:00
|
|
|
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
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("e065.py: " + str(euler_065()))
|
2019-07-18 20:23:44 +02:00
|
|
|
assert(euler_065() == 272)
|