Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.01 KB

493. Under The Rainbow.md

File metadata and controls

37 lines (25 loc) · 1.01 KB

Question

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).

Solution

The expected value of the number of distinct colours is the sum of the expected value of each colour getting picked, which is equal to one minus the probability that the colour hasn't been picked.

from functools import reduce
import operator

def p493():
    p = reduce(operator.mul, [(41+i)/(61+i) for i in range(10)], 1)
    return 7 * (1 - p)

Or a lightly more general solution:

from math import comb as C

def p493(n=70, m=20):
    assert n % 7 == 0
    return 7 * (1 - C(n - n // 7, m) / C(n, m))

Answer

6.818741802