Premium problem70. Competing Biased Coins

Medium Locked

Two players take turns flipping their own coin, player 1 first. Player 1's coin lands heads with probability p1, player 2's with p2. The first head ends the game. Return the probability player 1 wins.

Condition on the first round. Player 1 wins immediately, or both miss and the game restarts unchanged:

W=p1+(1−p1)(1−p2)W⇒W=p11−(1−p1)(1−p2)W = p_1 + (1-p_1)(1-p_2)W \quad\Rightarrow\quad W = \frac{p_1}{1 - (1-p_1)(1-p_2)}

Input

p1 = 0.5
p2 = 0.5

Output

0.6666666666666666

Premium problem

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

Implement solve(...)