-
Notifications
You must be signed in to change notification settings - Fork 1
/
65.py
32 lines (21 loc) · 739 Bytes
/
65.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import itertools
from sympy.ntheory.continued_fraction import continued_fraction_convergents
# e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, ... , 1, 2k, 1, ...]
def continued_fraction_for_e():
yield 2
yield 1
for k in itertools.count(1):
yield 2 * k
yield 1
yield 1
def tt(generator):
return list(itertools.islice(generator, 100))
if __name__ == "__main__":
approx_expansion = tt(continued_fraction_for_e())
import pprint
convergents = list(continued_fraction_convergents(approx_expansion))
pprint.pprint(list(enumerate(convergents)))
n = convergents[-1].numerator
print(f"That numerator again: {n}")
digit_sum = sum([int(c) for c in str(n)])
print(f"{digit_sum=}")