We have seen how Amy can win the coin-tossing game after leading 8-7. Let’s simulate the game and see what comes out.
AM <- 8
BE <- 7
itr <- 1000000
game <- replicate(itr,{
for (i in 1:5) {
card <- sample(c(1,0), 1, replace = TRUE, prob = c(1/2,1/2))
if(card ==1 ){
AM <- AM + 1
} else{
BE <- BE + 1
}
if(AM == 10| BE == 10 ) break
}
if(AM == 10){
counter <- 1
}else{
counter <- 0
}
})
mean(game)
0.6873
Not very far from the analytical solution.