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
(a) he bets 1 dollar each time (timid strategy).

#Probability of winning
p <- .4

#Probability of losing
q <- 1 -p

probability <- round(((1-((q/p)^1)))/(1-(q/p)^8),4)

print(probability)
## [1] 0.0203

(b) he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy).

# Probability Transition matrix
p <- matrix(c(1,0.6,0.6,0.6,0,0,0,0,0,0,0,0.4,0,0,0,0,0,0.4,0,0,0,0,0,0.4,1),nrow = 5, byrow=F)

# Initial vector
iv <- matrix(c(0,1,0,0,0), nrow=1, byrow = T)

#After 1st play
p1 <- iv %*% p

#After 2nd play
p2 <- p1 %*% p

#After 3rd play
p3 <- p2 %*% p

#After 4th play
p4 <- p3 %*% p

#After 5th play
p5 <- p4 %*% p

p5
##       [,1] [,2] [,3] [,4]  [,5]
## [1,] 0.936    0    0    0 0.064

Therefore, the probability of winning is .064

(c) Which strategy gives Smith the better chance of getting out of jail?

The bold strategy with .064 is better chance for Smith to get out of jail