A book's PnL follows a random walk: each day it moves +1 with probability p and -1 with probability 1 - p, independently, starting at 0. The game is losing: p < 1/2. You trade forever.
Compute the probability that the PnL ever reaches the level a > 0.
Two values p and a — p with at most 6 digits after the decimal point, a an integer.
One real number: the probability that the PnL ever reaches a, with relative error at most 1e-9. Note that the probability can be extremely small; your output must be relatively accurate, not just close to zero.
0.05 <= p <= 0.499999
1 <= a <= 150
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within a relative tolerance of 1e-09 of the expected value.
0.25 2
1.111111111111111e-01
0.4 5
1.316872427983540e-01