project_euler.problem_493.sol1 ============================== .. py:module:: project_euler.problem_493.sol1 .. autoapi-nested-parse:: Project Euler Problem 493: https://projecteuler.net/problem=493 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). ----- This combinatorial problem can be solved by decomposing the problem into the following steps: 1. Calculate the total number of possible picking combinations [combinations := binom_coeff(70, 20)] 2. Calculate the number of combinations with one colour missing [missing := binom_coeff(60, 20)] 3. Calculate the probability of one colour missing [missing_prob := missing / combinations] 4. Calculate the probability of no colour missing [no_missing_prob := 1 - missing_prob] 5. Calculate the expected number of distinct colours [expected = 7 * no_missing_prob] References: - https://en.wikipedia.org/wiki/Binomial_coefficient Attributes ---------- .. autoapisummary:: project_euler.problem_493.sol1.BALLS_PER_COLOUR project_euler.problem_493.sol1.NUM_BALLS project_euler.problem_493.sol1.NUM_COLOURS Functions --------- .. autoapisummary:: project_euler.problem_493.sol1.solution Module Contents --------------- .. py:function:: solution(num_picks: int = 20) -> str Calculates the expected number of distinct colours >>> solution(10) '5.669644129' >>> solution(30) '6.985042712' .. py:data:: BALLS_PER_COLOUR :value: 10 .. py:data:: NUM_BALLS :value: 70 .. py:data:: NUM_COLOURS :value: 7