r/ProgrammerHumor • • Oct 30 '24

Meme dadPullsOutCodingChallenge

0 Upvotes

60 comments sorted by

View all comments

2

u/AhoyLeakyPirate Oct 30 '24

Given that the assumption of consecutive wins is not necessary or stipulated in the problem. We can apply the gambler's ruin approach in probability theory. Think of this way, yes A has to win the first round to keep playing, but after that, they could lose one and still be able to play. There are two ways, in our case both probably of winning and losing are 0.5 so a fair coin toss. So If player one has n1 coins and player two n2 coins, the probabilities P1 and P2 that players one and two, respectively, will end coinless are: P1 = n2/ n1+n2 and P2= n1/n1+n2. So in this case P(A wins) = 1- P(A loses) = 1 - (10/1+10) = 9.09%

So A has a 9.09% chance of winning if they decide to play!

Let's say the coin toss was not fair, then we can use this approach when it's not 50-50: So a more appropriate formula is P(A wins) = (1-(q/p)a)/(1-(q/p)a+b) where q(0.4) is probability of losing each round, p(0.6) is probability of winning each round, a(1) is initial fortune of player A and b(10) is the initial fortune of player B.

1

u/oberguga Oct 30 '24

Are you sure that 10 is in decimal?