Probabilistically fair prize splitting for two-player coin toss Introduction


  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/4 and that of B is 1/4.


Challenge

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 X, Wa, Wb satisfy the following:


All numbers are non-negative integers.
X &gt; 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.

Test cases

X Wa Wb =&gt; Expected output
--------------------------
5  4  3 =&gt;  3/4  = 0.75
5  3  4 =&gt;  1/4  = 0.25
1  0  0 =&gt;  1/2  = 0.5
4  3  1 =&gt;  7/8  = 0.875
4  2  1 =&gt; 11/16 = 0.6875
6  4  2 =&gt; 13/16 = 0.8125
R, 36 32 bytes



function(X,A,B)pbeta(.5,X-A,X-B)


Try it online!

The closed formula from this answer suggested a natural probability distribution to use -- this is a Negative Binomial with \$X - W_b - 1\$ failures and \$X - W_a\$ successes, i.e., the probability that there are \$X - W_a\$ "successes" before there are \$X - W_b\$ "failures".

Further identities reduce the CDF of the negative binomial to the CDF of a beta distribution or in terms of the (regularized) incomplete beta function.