MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_057/sol1.py:23–44  ·  view source on GitHub ↗

returns number of fractions containing a numerator with more digits than the denominator in the first n expansions. >>> solution(14) 2 >>> solution(100) 15 >>> solution(10000) 1508

(n: int = 1000)

Source from the content-addressed store, hash-verified

21
22
23def solution(n: int = 1000) -> int:
24 """
25 returns number of fractions containing a numerator with more digits than
26 the denominator in the first n expansions.
27 >>> solution(14)
28 2
29 >>> solution(100)
30 15
31 >>> solution(10000)
32 1508
33 """
34 prev_numerator, prev_denominator = 1, 1
35 result = []
36 for i in range(1, n + 1):
37 numerator = prev_numerator + 2 * prev_denominator
38 denominator = prev_numerator + prev_denominator
39 if len(str(numerator)) > len(str(denominator)):
40 result.append(i)
41 prev_numerator = numerator
42 prev_denominator = denominator
43
44 return len(result)
45
46
47if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected