Premium problem57. Roll Until You Beat k

Medium Locked

Roll a fair m-sided die repeatedly until a roll comes out strictly greater than k. Return the expected sum of every roll, the stopping one included.

Split it in two:

  • each roll that fails to stop you is uniform on 1..k1..k, and you expect k/(m−k)k/(m-k) of them
  • the final roll is uniform on k+1..mk+1..m

Input

m = 6
k = 4

Output

10.5

Premium problem

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

Implement solve(...)