(a)he bets 1 dollar each time (timid strategy))
\[P = \frac{1 - \frac{q}{p}^j}{1 - \frac{q}{p}^N}\]
library(reticulate)
## Warning: package 'reticulate' was built under R version 3.4.4
p <- 0.4
q <- 1-p
j <- 1
N <- 8
P <- (1-(q/p)^j) / (1-(q/p)^N)
P
## [1] 0.02030135
import numpy as np
from random import random
p = 0.4
q = 1-p
j = 1
N = 8
P = (1-(q/p)**j) / (1-(q/p)**N)
print(P)
## 0.0203013481363997
(b)he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy)
run <- 10000
win <- 0
for (i in 1:run){
j <- 1
while (j > 0 & j < N){
if(runif(1) <= p){
j <- j + j
}else{
j <- j-j
}
}
if(j >= N){
win <- win + 1
}
}
win/run
## [1] 0.0621
(c)Which strategy gives Smith the better chance of getting out of jail?