library(glue)
Smith is in jail and has 1 dollar; he can get out on bail if he has 8 dollars. A guard agrees to make a series of bets with him. If Smith bets A dollars, he wins A dollars with probability .4 and loses A dollars with probability .6.
Find the probability that he wins 8 dollars before losing all of his money if
GamRuin = (1 - (0.6/0.4)^1) / (1 - (0.6/0.4)^8)
glue('The probability that he wins 8 dollars before losing all of his money if he bets 1 dollar each time (timid strategy) is {round(GamRuin, digits=4)}')
## The probability that he wins 8 dollars before losing all of his money if he bets 1 dollar each time (timid strategy) is 0.0203
m = matrix(c(1,0,0,0,0,
0.6,0,0.4,0,0,
0.6,0,0,0.4,0,
0.6,0,0,0,0.4,
0,0,0,0,1), ncol=5,nrow=5, byrow = TRUE)
rownames(m) = c("1","2","3","4","5")
colnames(m) = c("0","1","2","4","8")
m
## 0 1 2 4 8
## 1 1.0 0 0.0 0.0 0.0
## 2 0.6 0 0.4 0.0 0.0
## 3 0.6 0 0.0 0.4 0.0
## 4 0.6 0 0.0 0.0 0.4
## 5 0.0 0 0.0 0.0 1.0
initial = matrix(c(0, 1, 0, 0, 0), ncol=5,nrow = 1,byrow = TRUE)
initial
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 1 0 0 0
m1 = initial %*% m
m2 = m1 %*% m
m3 = m2 %*% m
m4 = m3 %*% m
m4
## 0 1 2 4 8
## [1,] 0.936 0 0 0 0.064
glue('The probability that he wins 8 dollars before losing all of his money if he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy) is {m4[5]}.')
## The probability that he wins 8 dollars before losing all of his money if he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy) is 0.064.
The bold strategy of betting each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars gives Smith the better chance of getting out of jail.