Convergents of e

Problem 65

The square root of 2 can be written as an infinite continued fraction.
The infinite continued fraction can be written, , indicates that 2 repeats ad infinitum. In a similar way, .
It turns out that the sequence of partial values of continued fractions for square roots provide the best rational approximations. Let us consider the convergents for .
Hence the sequence of the first ten convergents for are:
What is most surprising is that the important mathematical constant,
.
The first ten terms in the sequence of convergents for e are:
The sum of digits in the numerator of the 10th convergent is .
Find the sum of digits in the numerator of the 100th convergent of the continued fraction for .
from functools import reduce

def run():
    l = reduce(lambda l1, l2: l1 + l2, [[1, x, 1] for x in range(2, 100, 2)])

    n, d = 1, l[98]
    for i in range(97, -1, -1):
        n, d = d, n + d * l[i]

    return sum(map(lambda x: ord(x) - ord("0"), list(str(n + 2 * d))))