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:
I will run 500 simulations for determining the probability.
p = vector("numeric", 500)
bets = vector("numeric", 500)
for (i in 1:500) {
#start = 1, win 8
d = 1
num_of_bet = 0
while (!(d == 0 || d >= 8)) {
num_of_bet = num_of_bet + 1
winLose = runif(1, min=0, max=1)
if(winLose <= 0.4) {
d = d + 1 #win
}
else {
d = d - 1 #lose
}
}
#this simulation result:
if (d == 8) { #if win, set to 1
p[i] = 1
}
else { #else, set to 0
p[i] = 0
}
bets[i] = num_of_bet
}
#store the probablity
timid_strategy_p = sum(p)/500
paste("With with timid strategy, the probability that smith win 8 dollors: ", timid_strategy_p)
## [1] "With with timid strategy, the probability that smith win 8 dollors: 0.026"
p = vector("numeric", 500)
bets = vector("numeric", 500)
for (i in 1:500) {
#start = 1, win 8
d = 1
num_of_bet = 0
while (!(d == 0 || d >= 8)) {
num_of_bet = num_of_bet + 1
winLose = runif(1, min=0, max=1)
if(winLose <= 0.4) {
d = d * 2 #win
}
else {
d = 0 #lose
}
}
#this simulation result:
if (d == 8) { #if win, set to 1
p[i] = 1
}
else { #else, set to 0
p[i] = 0
}
bets[i] = num_of_bet
}
bold_strategy_p = sum(p)/500
paste("With bold strategy, the probability that smith win 8 dollors: ",bold_strategy_p )
## [1] "With bold strategy, the probability that smith win 8 dollors: 0.06"
if (bold_strategy_p > timid_strategy_p){
paste("The bold strategy gives Smith the better chance of getting out of jail by probability: ", (bold_strategy_p - timid_strategy_p) )
}
## [1] "The bold strategy gives Smith the better chance of getting out of jail by probability: 0.034"
if(bold_strategy_p <= timid_strategy_p) {
paste("The timid strategy gives Smith the better chance of getting out of jail by probability: ", abs(bold_strategy_p - timid_strategy_p) )
}