data_605_hw10

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)

This represents a Markov chain solution. We can apply the formula from textbook p.489.

z <- 1
p <- .4
q <- .6
M <- 8

solution <- ((q/p)^z - 1) / ((q/p)^M - 1)

print(glue("The probability of winning $8 before losing all of his money if Smith applied the timid strategy is about ", round({solution}*100, 2), "%"))
## The probability of winning $8 before losing all of his money if Smith applied the timid strategy is about 2.03%

(b)

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

Essentially, he has to win 3 times consecutively, i.e. $1 -> $2 -> $4 -> $8. The solution is simply p^3, but we can simulate the situation 100000 times to confirm the probability.

solution = .4^3

random_walk = 100000
x = vector(mode = "list", length = random_walk)

for(i in 1:random_walk){
    
    x[[i]] = purrr::reduce(sample(c(0, 1), 3, prob = c(0.6, 0.4), replace = TRUE), `+`)
        
}

y = x %>% 
    unlist %>% 
    data.frame %>% 
    table() %>%
    as.data.frame %>% 
    select("num_of_consecutive_wins" = ".", Freq)
y
##   num_of_consecutive_wins  Freq
## 1                       0 21345
## 2                       1 43506
## 3                       2 28684
## 4                       3  6465
simulation = (y %>% dplyr::filter(num_of_consecutive_wins == 3) %>% .$Freq) / random_walk

print(glue("The probability of bold strategy is equal to p^3 or ", round({solution}*100, 2), "%. The result of the {random_walk} simulations is extremely close, i.e. ", round({simulation}*100, 2), "%."))
## The probability of bold strategy is equal to p^3 or 6.4%. The result of the 1e+05 simulations is extremely close, i.e. 6.46%.

(c)

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

Obviously, the bold strategy would offer Smith a better chance of getting out of jail, i.e. 6.4% > 2%