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

Function solution

project_euler/problem_121/sol1.py:29–60  ·  view source on GitHub ↗

Find the maximum prize fund that should be allocated to a single game in which fifteen turns are played. >>> solution(4) 10 >>> solution(10) 225

(num_turns: int = 15)

Source from the content-addressed store, hash-verified

27
28
29def solution(num_turns: int = 15) -> int:
30 """
31 Find the maximum prize fund that should be allocated to a single game in which
32 fifteen turns are played.
33 >>> solution(4)
34 10
35 >>> solution(10)
36 225
37 """
38 total_prob: float = 0.0
39 prob: float
40 num_blue: int
41 num_red: int
42 ind: int
43 col: int
44 series: tuple[int, ...]
45
46 for series in product(range(2), repeat=num_turns):
47 num_blue = series.count(1)
48 num_red = num_turns - num_blue
49 if num_red >= num_blue:
50 continue
51 prob = 1.0
52 for ind, col in enumerate(series, 2):
53 if col == 0:
54 prob *= (ind - 1) / ind
55 else:
56 prob *= 1 / ind
57
58 total_prob += prob
59
60 return int(1 / total_prob)
61
62
63if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

countMethod · 0.80

Tested by

no test coverage detected