## installed_and_loaded.packages.
## prettydoc TRUE
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
- he bets 1 dollar each time (timid strategy).
p <- 0.4
q <- 1 - p
z <- 1
M <- 8
(q_z <- (((q/p)^z - 1)/((q/p)^M - 1)))## [1] 0.02030135
- he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy).
p <- 0.4
M <- 8
wins <- 0
trials <- 1e+05
for (i in 1:trials) {
z <- 1
while (z > 0 & z < M) {
if (runif(1) <= p) {
z <- z + z
} else {
z <- z - z
}
}
if (z >= M) {
wins <- wins + 1
}
}
wins/trials## [1] 0.06443
- Which strategy gives Smith the better chance of getting out of jail?
He should go bold!