//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 problem can thought of as a markov chain, where each state is a different dollar amount (8 states, one for each dollar amount.) The goal therefore, is to find the probability that the chain reaches state 8 (sweet freedom) BEFORE reaching state 0 (incarserated AND broke)
Win = 0.4
Lose = 0.6
Goal = 8.0
for (i in seq(1, 7)){
print((1-(Lose/Win)^i)/(1-(Lose/Win)^Goal))
}
## [1] 0.02030135
## [1] 0.05075337
## [1] 0.0964314
## [1] 0.1649485
## [1] 0.267724
## [1] 0.4218874
## [1] 0.6531324
#the first printed item is the probability of getting to state 8 before falling to state 0, so something in the neighborhood of 2%
#(b) he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy).
#This is a simple probability question, in order to win this way, jailbird would have to win 3 times in a row, turning his $1 into $2, then $2 into $4, and finally $4 into freedom. because he is betting everything every time he plays, even a single loss will result in him having no money to bet and the game being over.
#probability of winning 1 AND winning 2 AND winning 3
Win * Win * Win
## [1] 0.064
#The chance of winning this way is %6.4
###(c) Which strategy gives Smith the better chance of getting out of jail?
#based on the above calculation, the bold strategy gives jailbird a better chance of escaping his current situation.