Exercise 1 (Simple gambler’s ruin) Suppose someone plays the following gambling game. They bet \(1\) pound on a fair flip of a coin and win \(1\) pound if it comes up heads, and lose if come up tails. They start with \(1\) pound, and stop playing once they have reached \(5\) pounds or have no money left. Use R to run simulations to estimate the probability of ending the game with no money left.


Solution. First, we define a function that gives the result of one iteration when you have \(x\) dollars. Then we run this game function in a while-loop until we are bankrupt or get to win a five pound note. We want to run the game function with the starting amount of \(1\), many times and then take an average. We use the replicate function.
play <- function(x){
x <- 2*(rbinom(1,1,0.5)) -1 +x;
x
}
game <- function(x){
while( x >0 && x <5){
x <- play(x);
}
x
}
y = replicate(1000, game(1))
backrupt=sum(y==0)/1000
win=sum(y==5)/1000


backrupt
## [1] 0.798
win
## [1] 0.202

The following version of the gambler’s ruin problem was Huygen’s formulation of a problem discussed in a correspondence between Pascal and Fermat: Each player starts with 12 points, and a successful roll of the three dice for a player (getting an 11 for the first player or a 14 for the second) adds one to that player’s score and subtracts one from the other player’s score; the loser of the game is the first to reach zero points. What is the probability of victory for each player? See A note on the history of the gambler ruin problem.

Exercise 2 Using R, estimate the probability that first player is victorious.

Of course you can compute the probabilities of getting \(11\) and \(14\), but you can electronically roll dice:

sample(6, 10, replace=TRUE)
##  [1] 3 4 1 1 3 3 4 1 1 1


Exercise 3 (Three players) Suppose three players each of which start with \(5\) points, play a game where they have equal probability of winning. The winner takes \(1\) point from each of the two losers. They stop playing when any at least one player has no more money left. On average, how long do they play?


For more information on the general case of \(n\) players see The asymmetric n-player gambler’s ruin problem with equal initial fortunes.


Version: 5 October 2020