Adam (A) and Bubbler (B) are playing coin toss, where the one who wins 5 times first would win the prize of $32. If the game is aborted when the scores are
A:B = 4:3, how should they distribute the prize? Assume the coin toss is fair, so the winning chance of either player is 1/2 for each game.
The answer is:
Adam should take $24 and Bubbler should take $8. Possible cases are as follows:
A wins (score 5:3, chance 1/2): A wins the prize B wins (score 4:4) then A wins (score 5:4, chance 1/4): A wins the prize B wins (score 4:4) then B wins (score 4:5, chance 1/4): B wins the prize
Therefore, the chance of A winning is
3/4and that of B is
In order to do the fair splitting of prizes, we should compute the chance of winning the prize for each player. Given the following information,
X, how many times a player should win coin toss to win the prize
Wa, how many times player A has already won
Wb, how many times player B has already won
compute the chance of player A winning the prize.
Input and output
You can assume the three input numbers
Wb satisfy the following:
- All numbers are non-negative integers.
X > max(Wa, Wb), i.e. the game hasn't finished already.
You can choose to output a fraction or a floating-point number.
Scoring and winning criterion
Standard code-golf rules apply. Shortest code in bytes wins.
X Wa Wb => Expected output -------------------------- 5 4 3 => 3/4 = 0.75 5 3 4 => 1/4 = 0.25 1 0 0 => 1/2 = 0.5 4 3 1 => 7/8 = 0.875 4 2 1 => 11/16 = 0.6875 6 4 2 => 13/16 = 0.8125