Calculates the expected number of distinct colours >>> solution(10) '5.669644129' >>> solution(30) '6.985042712'
(num_picks: int = 20)
| 32 | |
| 33 | |
| 34 | def 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 | |
| 52 | if __name__ == "__main__": |