stop_at, the player pulls a token from a bag and adds its value to the score. Each token's value is a random integer from 1 to max_step, every value equally likely, and every pull is independent of the others.
As soon as the score reaches stop_at or more, the player stops.
Return the probability that the final score is at most cap. Answers within 10⁻⁵ of the true value are accepted.cap=4, stop_at=1, max_step=8 → 0.5
The player draws exactly one token: 4 of the 8 equally likely values (1 to 4) keep the score at or below 4, so the chance is 4/8 = 0.5.
cap=3, stop_at=2, max_step=2 → 1.0
A first token of 2 (chance 1/2) ends the game at 2. A first token of 1 is followed by a 1 or a 2, ending at 2 or 3. The score never goes above 3, so the chance is 1.0.
cap=2, stop_at=2, max_step=2 → 0.75
The only bad outcome is a 1 followed by a 2, which ends at 3. Its chance is 1/2 · 1/2 = 0.25, so the answer is 0.75.
cap=4, stop_at=1, max_step=8
0.5
Run checks the first 3 tests in your browser. Submit checks all 66 tests on the server, hidden ones included.