Premium problem65. Expected Equal Neighbours

Medium Locked

Shuffle a objects of type A together with b of type B into a random order. Return the expected number of adjacent pairs whose two items share a type.

Linearity of expectation does all the work: there are a+b−1a + b - 1 adjacent positions, and each one holds a matching pair with the same probability.

P(match)=a(a−1)+b(b−1)(a+b)(a+b−1)P(\text{match}) = \frac{a(a-1) + b(b-1)}{(a+b)(a+b-1)}

Input

a = 5
b = 5

Output

4.0

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)