Created
September 26, 2022 13:12
-
-
Save ylxdzsw/2b93b548ddf24a11f5372e652c73420b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # draw 100 balls of 40 colors, where the color of each ball is uniformly random, the probability of drawn at least 1 ball of each color | |
| def g(colors, balls): | |
| total_colors = colors | |
| cache = {} | |
| def f(rest_colors, rest_balls): | |
| if (rest_colors, rest_balls) in cache: | |
| return cache[(rest_colors, rest_balls)] | |
| if rest_colors == 0: | |
| return 1 | |
| if rest_balls == 0: | |
| return 0 | |
| result = ((rest_colors / total_colors) * f(rest_colors - 1, rest_balls - 1) + | |
| (1 - (rest_colors / total_colors)) * f(rest_colors, rest_balls - 1)) | |
| cache[(rest_colors, rest_balls)] = result | |
| return result | |
| return f(colors, balls) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment