Skip to content

Commit

Permalink
add euler065 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
kailanefelix committed Nov 28, 2021
1 parent e848416 commit 542b46b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions euler0XX/euler065.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from fractions import Fraction
from itertools import count

def terms_for_e():
for k in count(2, 2):
yield 1
yield k
yield 1

def drop(sequence, n):
for _, value in zip(range(n), sequence):
pass
yield from sequence

def take(sequence, n):
for _, value in zip(range(n), sequence):
yield value

def continued_fractions(a0, an):
frac = Fraction(0)
for ai in reversed(an):
frac = Fraction(1, ai + frac)
return a0 + frac

terms = [*take(terms_for_e(), 99)]
e_fraction = continued_fractions(2, terms)
digits = str(e_fraction.numerator)
print(sum(int(n) for n in digits))

0 comments on commit 542b46b

Please sign in to comment.