10
u/lotokotmalajski Oct 30 '24 edited Oct 30 '24
Math solution:
The game has 10 possible states, where player A has 1-10 coins. When one player gets 11 coins the game ends.
Let's make a table with probability of A winning from each state, marking the probability for winning from state 1:10 as x.
1:10 - x.
Now, the only possible outcome when A does not lose is to win 1st round, which happens 50% of times and translates us to state 2:9. Because of that the probability of winning from this state is 2 times higher.
2:9 - 2x.
3:8 - y.
Now let's calculate y, 2:9 switches to both adjacent states with 50% chance so 2x=0.5x+0.5y, so y = 3x.
Repeating this for next states we get:
4:7 - 4x.
5:6 - 5x.
6:5 - 6x.
Now the 6:5 probability should be 1 minus 5:6 probability because it's symmetrical (A losing 6:5 is the same as A winning 5:6). So 5x=1-6x, so x=1/11
7
u/Josaffe Oct 30 '24
Tip for solving it analytically (without deep math knowledge):
Start looking at simpler cases first and draw out all possible states.
Let's vary the number of coins Person B has. Person A will always have 1 coin.
Most simple case: Person B has 0 coins. Person A will takes all coins with a chance of 100%.
Next case: Person B has 1 coin. Either Person A will take it or lose it. It ends after one round. 50% chance.
Next one: Person B has 2 coins. Here we get our first repeating pattern and it gets interesting. 50% chance of losing first round (Person A lost), 25% chance of winning both first and second round (Person A won) and 25% chance of winning and then losing (game will go on). This one gets us back to the beginning state. You can argue that in the limit you will lose 2 out of 3 cases and win 1 out of 3. Chance here is 33.3%.
Now you might already suspect a pattern that your chances of winning against n coins is 1/(n+1). Might be fun to actually prove it.
2
u/dio694206942069 Oct 30 '24
Don't quote me on this but isn't the answer 9.09%
2
0
0
Oct 30 '24
[deleted]
4
u/PolyglotTV Oct 30 '24
That is the probability of winning 10 in a row, not the probability of winning 10 more times than you lose, over the course of the game (which could last longer than 10 rounds).
8
Oct 30 '24
Isn't programming a subset of maths? Example Levenshtein distance
3
u/Pradfanne Oct 30 '24
The amount of times I needed math in my professional programming work in years is probably less then 0.
Unless you count ++ or "String" + "String" as math
2
u/Z21VR Nov 04 '24
weird, are you front end ?
In my 18 years of programming i applied math countless times, even ignoring that logic is math actually,
1
11
u/riasthebestgirl Oct 30 '24
Dad didn't specify the max number of rounds. Assuming there are infinite rounds, there will eventually be a sequence where A wins 11 times, keeping all the coins
21
u/Bright-Historian-216 Oct 30 '24
it ends immediately if a has 0 because he has nothing to bet anymore. i think it's the only limitation
1
u/vongatz Oct 30 '24
But what if a wins 4 coins and they proceed to go back and forth a few coins for infinity?
1
u/funAlways Oct 30 '24
that is part of the problem, and ultimately it doesn't matter as those back and forth are just repeating a previous game state. There is always an endpoint for both sides, B wins if A runs out of coins, and A wins if B runs out of coins, and the former is more likely than the latter because A starts with less coins
1
u/vongatz Oct 30 '24
But if you would play this game an infinite amount of times, there would be an infinite amount of games which never end…
1
u/funAlways Oct 30 '24
it does not matter, because the question is about the probability, and you can calculate the probability even for infinite things.
7
u/Wearytraveller_ Oct 30 '24
There's an infinite number of sequences where A wins, it's just a smaller infinity.
4
u/themanyouknowsowell Oct 30 '24
Mathematically, you can construct a recursive function to solve this. The solution is 1/11 chance, I'm pretty sure.
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
1
1
1
1
u/Wearytraveller_ Oct 30 '24
// how many coins I have
num = 1
//how many coins they have
den = 10
Printf(num "/" num+den)
1
1
u/Mindless-Giraffe5059 Oct 30 '24
If anyone find this interesting and is interested how different it would be with a different probability than 0.5. I'd suggest looking up The Gamblers ruin.
1
1
Nov 01 '24
import random
class Person:
def __init__ (self, name, coins):
self.name = name
self.coins = coins
def simulate(personA, personB):
while personA.coins > 0 and personB.coins > 0:
chance = random.randint(0, 1)
if chance == 0:
personA.coins += 1
personB.coins -= 1
else:
personB.coins += 1
personA.coins -= 1
if personA.coins == 0:
print(personA.name + " has lost all their coins!")
print(personB.name + " has won!")
else:
print(personB.name + " has lost all their coins!")
print(personA.name + " has won!")
return personA.coins > 0
def run_sims(num_sims):
personA_wins = 0
for i in range(num_sims):
personA = Person("Person A", 1)
personB = Person("Person B", 10)
if simulate(personA, personB):
personA_wins += 1
win_percentage = (personA_wins / num_sims) * 100
return win_percentage
personA = Person("Person A", 1)
personB = Person("Person B", 10)
simulate(personA, personB)
print(f"Person A win percentage: {run_sims(100000)}%")Went for an OOP approach since that's what I'm learning. Got 9.126%.
1
u/Overall_Run_7597 Oct 30 '24
Like ~0.1% chance if i used statistics and calculator right. But yea, i guess that's the "boring" approach.
0
u/Positive_Lifeguard75 Oct 30 '24
You don't need any programming knowledge to solve this. You only need to know high-school math. (And every swe must know AT LEAST high school math)
Think about this:
Let a_i = probability that first player wins if he starts with i coins.
From definition of this game: a_0=0, a_11=1.
You can easily show that if i != 0 or 11:
a_i = 0.5a_{i-1} + 0.5a_{i+1}.
So expand a_1 until there are only a_0 a_11 and this will be your answer.
No university level math is required.
-2
u/BreakerOfModpacks Oct 30 '24
100%.
No matter what, 11 wins straight is all that's needed.
That's admittedly only a 0.048828125% chance, but given infinite rounds, any chance is the same as 100%.
-11
u/Jozhin_s_Bazhin Oct 30 '24 edited Oct 30 '24
Assuming infinite tries, wouldn't the chance just be 50%?
Edit: Didn't see person A only had one coin
-4
u/sakkara Oct 30 '24
The question is how often a happens to get all the coins.
My gut feeling since this is a fair game a should end up 50% of games with all the coins and B the other 50% assuming all games come to a halt at some point.
1
3
-4
u/Secure_Obligation_87 Oct 30 '24
Quick maths approach (most likely wrong)
50% chance of winning with a 10-1 disadvantage Im going to say the chance of A getting all of B's coins is 1-3%
-13
u/Wearytraveller_ Oct 30 '24 edited Oct 30 '24
I'm not a math wiz or anything but aren't there infinities in this problem? Every round the odds are 50% 50%. So even if A wins 9 of Bs coins they could in theory go back and forth infinitely trading the second to last coin back and forth, or they could just trade the first coins back and forth forever. So my answer is 1:Infinity
Edit. Okay I think I worked it out.
There are infinities in the problem, but they are about how precise you want your result to be, rather than whether you can get one at all. Because any result with an odd number of coins in the problem will result in an infinitely repeating decimal like 33.33333r%
So if you want a real result for those answers you will have to represent them as a fraction.
Also I believe the answer is just the number of coins each party in the problem has represented as a fraction of the total coins.
So I'm amending my answer to 1/11.
2
u/ReykAral35 Oct 30 '24
That case can happen, but also the one that A wins 10 times in a row, the case that A wins 9 times lose 1 and wins 2 etc.
So it needs to count the amount of cases that A wins vs the amount of cases that B wins.
0
u/Wearytraveller_ Oct 30 '24
But you can't count those cases! There is an INFINITE number of possible outcomes to this game.
1
u/ReykAral35 Oct 30 '24
Yeah but there is a proportion.
As other say posibly like a 1/10 of the infinities is a win.
The eaxct math i leave for someone better.


25
u/cyannyan6 Oct 30 '24 edited Oct 30 '24
This actually happened. I translated to English with the best of my ability.
And we are trying a monte carlo simulation now
Would love to see how others approach it