Premium problem62. Going Bankrupt Mid-Game

Hard Locked

You start with wealth w and roll a fair six-sided die n times. An even face adds its value to your wealth; an odd face subtracts it. Return the probability that your wealth is zero or below at any point during the game.

Once you are wiped out you stay wiped out, so absorb that state rather than letting wealth recover. Work forwards over the rolls, tracking the distribution of wealth among the runs still alive.

Input

w = 5
n = 3

Output

0.31018518518518523

Premium problem

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

Implement solve(...)