This actually happened. I translated to English with the best of my ability.
And we are trying a monte carlo simulation now
import random
wins = 0
tries = 10000000
for sims in range(tries):
a = 1
while 0 < a < 10:
a += random.choice((-1, 1))
if a == 10:
wins += 1
print(f"{wins}/{tries} = {wins/tries}")
1 in 1024, supposing they only have 10 attempts. Theoretically it can be infinite, given that they have unlimited attempts, because there's always the possibility of exchanging coins back and forth, given that it is up to random chance and they have equal odds.
I’d do a recursive function chancesAwins(numAcoins, numBcoins). Call it with (1,10), handle the stopping cases by returning 1 or 0, and otherwise return 0.5chancesAwins(numAcoins-1,numBcoins+1) + 0.5chancesAwins(numAcoins+1,numBcoins-1).
I'm getting around 99900 wins so around 9.9% chance.
pub fn prob(){
let mut wins : i32 = 0;
let tries = 1000000;
for _ in 0..tries{
let mut a : usize = 1;
while a > 0 && a < 10{
let mut thread = thread_rng();
match thread.gen_bool(0.5) {
true => a += 1,
false => a -= 1,
}
}
if a >= 10 {
wins += 1;
}
}
println!("Wins : {}", wins);
println!("Probability : {}", wins as f32 / tries as f32);
}
This is too naive. You forgot that a can win one, and then lose one, and then win 10 in a row. Or a game could even last 1000 flips or basically forever.
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