Problem 424900 · easy · Level 04 Non-Linear Data Structures

Ordering Jackets by Height

normal distribution · cumulative distribution function · math.erf · areas as probabilities

A rowing club orders team jackets in several sizes. Each size fits a band of heights: boundaries is an increasing list of heights in centimetres that separate the sizes, so k boundaries make k + 1 sizes: below the first boundary, between each pair of neighbouring boundaries, and above the last one.

The club's members have heights that follow a normal distribution with mean mu and standard deviation sigma. Write size_shares(mu, sigma, boundaries) that returns a list of k + 1 floats: the share of members in each size band, from the smallest size to the largest.

Use math.erf (or statistics.NormalDist); a height exactly on a boundary has probability 0, so it does not matter which band it belongs to.

Examples

Input:  mu = 170, sigma = 8, boundaries = [162, 178]
Output: [0.15865525393145707, 0.6826894921370859, 0.15865525393145707]
Explanation: the middle band is mu ± one standard deviation, which holds about 68%
of a normal distribution; the rest is split evenly between the two tails.

Input:  mu = 170, sigma = 8, boundaries = [154, 170, 186]
Output: [0.02275013194817921, 0.4772498680518208, 0.4772498680518208, 0.02275013194817921]

Constraints

  • 0 < sigma, and mu and all boundaries between -10**4 and 10**4
  • 0 <= len(boundaries) <= 50, strictly increasing
  • floats are compared with a tolerance of 1e-6

Goals

  • Turn a normal distribution's CDF into probabilities of intervals
  • Compute the normal CDF with math.erf after standardising
  • Check that the probabilities of all the bands add up to 1
Starting Python…