<jupyter_start><jupyter_text>Problem 493 Under The Rainbow$70$ coloured balls are placed in an urn, $10$ for each of the seven rainbow colours.What is the expected number of distinct colours in $20$ randomly picked balls?Give your answer with nine digits after the decimal point (a.bcdefghij). SolutionDefine total number of balls $n$ and number of balls of each color $m$. We can count probability that certain color will not among the $k$ picked balls:$$\frac{\binom{n - m}{k}}{\binom{n}{k}} = \frac{\frac{(n - m)!}{k! (n - m - k)!}}{\frac{n!}{k! (n - k)!}} = \frac{k! (n - k)! (n - m)!}{k! n! (n - m - k)!} = \frac{(n - k)! (n - m)!}{n! (n - m - k)!}$$As $n!$ so large, this expression could be rewritten as:$$\frac{(n - k)! (n - m)!}{n! (n - m - k)!} = \frac{\displaystyle\prod_{i = n - m - k + 1}^{n - k} i}{\displaystyle\prod_{i = n - m + 1}^{n} i} = \displaystyle\prod_{i = n - m + 1}^{n} \frac{i - k}{i}$$Now we need opposite of this probability as certain color should be among picked balls and as we have 7 colors it should be multiplied by $7$:$$7 \left(1 - \displaystyle\prod_{i = n - m + 1}^{n} \frac{i - k}{i}\right)$$<jupyter_code>from math import prod
def compute(n: int, k: int) -> float:
    return round(7 * (1 - prod((i - k) / i for i in range(n // 7 * 6 + 1, n + 1))), 9)
compute(70, 20)
%timeit -n 100 -r 1 -p 6 compute(70, 20)<jupyter_output>1.738 µs ± 0 ns per loop (mean ± std. dev. of 1 run, 100 loops each)
{'fraction_non_alphanumeric': 0.18911374738311235, 'fraction_numerical': 0.03210048848569435, 'mean_word_length': 3.385321100917431, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '533238', 'license': 'MIT', 'n_tokens_mistral': 570, 'n_tokens_neox': 504, 'n_words': 211, 'path': 'problems/0493/solution.ipynb', 'repo_name': 'Dynortice/didactic-rotary-phone', 'size': '1433'}