Skip to content
Prev Previous commit
Next Next commit
Move up explanation to module code block
  • Loading branch information
peteryao7 committed Oct 16, 2020
commit d81a171fcb58997e8e6e47085390a3b5bbd1d50b
35 changes: 20 additions & 15 deletions project_euler/problem_065/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,31 @@

Find the sum of the digits in the numerator of the 100th convergent
of the continued fraction for e.
"""

-----

def solution(max: int = 100) -> int:
"""
The solution mostly comes down to finding an equation that will generate
the numerator of the continued fraction. For the i-th numerator, the
pattern is:
The solution mostly comes down to finding an equation that will generate
the numerator of the continued fraction. For the i-th numerator, the
pattern is:

n_i = m_i * n_(i-1) + n_(i-2)

n_i = m_i * n_(i-1) + n_(i-2)
for m_i = the i-th index of the continued fraction representation of e,
n_0 = 1, and n_1 = 2 as the first 2 numbers of the representation.

for m_i = the i-th index of the continued fraction representation of e,
n_0 = 1, and n_1 = 2 as the first 2 numbers of the representation.
For example:
n_9 = 6 * 193 + 106 = 1264
1 + 2 + 6 + 4 = 13

n_10 = 1 * 193 + 1264 = 1457
1 + 4 + 5 + 7 = 17
"""

For example:
n_9 = 6 * 193 + 106 = 1264
1 + 2 + 6 + 4 = 13

n_10 = 1 * 193 + 1264 = 1457
1 + 4 + 5 + 7 = 17
def solution(max: int = 100) -> int:
"""
Returns the sum of the digits in the numerator of the max-th convergent of
the continued fraction for e.

>>> solution(9)
13
Expand All @@ -75,7 +80,7 @@ def solution(max: int = 100) -> int:

def sum_digits(num: int) -> int:
"""
Adds all the single digits of an int together.
Returns the sum of every digit in num.

>>> sum_digits(1)
1
Expand Down