CUNY MSDA DATA 605 HW 10

Nicholas Schettini

November 4, 2018

library(reticulate)
import numpy as np
from random import random

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:

  1. he bets 1 dollar each time (timid strategy)

\[P = \frac{1 - \frac{q}{p}^j}{1 - \frac{q}{p}^N}\] in R:

p <- 0.4
q <- 1-p
j <- 1
N <- 8

P <- (1-(q/p)^j) / (1-(q/p)^N)
P
## [1] 0.02030135

In Python:

p = 0.4
q = 1-p
j = 1
N = 8
P = (1-(q/p)**j) / (1-(q/p)**N)
print(P)
## 0.0203013481363997
  1. he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy)
runs <- 10000
wins <- 0 

for (i in 1:runs){
  j <- 1
  while (j > 0 & j < N){
    if(runif(1) <= p){
      j <- j + j
    }else{
      j <- j-j
    }
  }
  if(j >= N){
    wins <- wins + 1
  }
}

wins/runs
## [1] 0.0632
  1. The bold stragety

Ref: https://www.countbayesie.com/blog/2015/3/3/6-amazing-trick-with-monte-carlo-simulations http://people.sc.fsu.edu/~jpeterson/monte_carlo_simulation.pdf