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

Function solution

project_euler/problem_100/sol1.py:16–44  ·  view source on GitHub ↗

Returns the number of blue discs for the first arrangement to contain over min_total discs in total >>> solution(2) 3 >>> solution(4) 15 >>> solution(21) 85

(min_total: int = 10**12)

Source from the content-addressed store, hash-verified

14
15
16def solution(min_total: int = 10**12) -> int:
17 """
18 Returns the number of blue discs for the first arrangement to contain
19 over min_total discs in total
20
21 >>> solution(2)
22 3
23
24 >>> solution(4)
25 15
26
27 >>> solution(21)
28 85
29 """
30
31 prev_numerator = 1
32 prev_denominator = 0
33
34 numerator = 1
35 denominator = 1
36
37 while numerator <= 2 * min_total - 1:
38 prev_numerator += 2 * numerator
39 numerator += 2 * prev_numerator
40
41 prev_denominator += 2 * denominator
42 denominator += 2 * prev_denominator
43
44 return (denominator + 1) // 2
45
46
47if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected