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

  1. he bets 1 dollar each time (timid strategy).
  2. he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy).
  3. Which strategy gives Smith the better chance of getting out of jail?
#a - he bets 1 dollar each time 
timid <- function() {
  dollars <- 1
  while (dollars > 0 && dollars < 8) {
    if (runif(1) <= 0.4) {
      dollars <- dollars + 1
    } else {
      dollars <- dollars - 1
    }
  }
  return(dollars == 8) #t/f
}

# b - bold strategy
bold <- function() {
  dollars <- 1
  while (dollars > 0 && dollars < 8) {
    max <- min(dollars, 8 - dollars)
    bet <- sample(1:max, 1)
    if (runif(1) <= 0.4) {
      dollars <- dollars + bet
    } else {
      dollars <- dollars - bet
    }
  }
  return(dollars == 8)
}

sim <- 1000000

timid_results <- replicate(sim, timid())
bold_results<- replicate(sim, bold())

print(p_timid <- mean(timid_results))
## [1] 0.020595
print(p_bold <- mean(bold_results))
## [1] 0.050592

C. It appears the bold strategy gives Smith the better chance of getting out of jail at 0.05 compared to the timid strategy of 0.02.