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

Function solution

project_euler/problem_493/sol1.py:34–49  ·  view source on GitHub ↗

Calculates the expected number of distinct colours >>> solution(10) '5.669644129' >>> solution(30) '6.985042712'

(num_picks: int = 20)

Source from the content-addressed store, hash-verified

32
33
34def solution(num_picks: int = 20) -> str:
35 """
36 Calculates the expected number of distinct colours
37
38 >>> solution(10)
39 '5.669644129'
40
41 >>> solution(30)
42 '6.985042712'
43 """
44 total = math.comb(NUM_BALLS, num_picks)
45 missing_colour = math.comb(NUM_BALLS - BALLS_PER_COLOUR, num_picks)
46
47 result = NUM_COLOURS * (1 - missing_colour / total)
48
49 return f"{result:.9f}"
50
51
52if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected