13
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 is1/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 prizeWa
, how many times player A has already wonWb
, 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 > 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 => 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
Can
Wa
andWb
be taken as a complex numberWa+j*Wb
, wherej
is the imaginary unit? – Luis Mendo – 2019-12-23T00:44:20.790@LuisMendo That's OK. I/O is flexible as always. – Bubbler – 2019-12-23T01:37:36.190
May i output
6/8
instead of3/4
? – tsh – 2019-12-23T02:35:09.007@tsh Yes, it's fine. – Bubbler – 2019-12-23T03:16:57.353
@Bubbler What about binary or hex "decimals"? – wizzwizz4 – 2019-12-23T11:21:17.573
@wizzwizz4 If it means writing 0.75 as $ 0.11_2 $, I don't think there's any problem allowing it. – Bubbler – 2019-12-24T14:16:52.203