St. Petersburg Lottery, probability python, -


the following question references project euler problem 499, can found here. here problem in nutshell: gambler starts s dollars, , can gamble in costs m dollars play. once starts play, pays m dollars dealer, , gets 1$ pot. flips fair coin. if coin lands on heads, pot doubled, , plays again. if coin lands on tails, gambler takes entirety of pot, , has pay m dollar starting fee again dealer pot back. probability never runs out of money m = 2$ , s = 2$?

my strategy create python script branching probability tree tell me possible outcomes on branch down line (for example, possibilities after 25 coin tosses). here script:

def play_game(initial_funds, price_to_play, iterations):     prob_tree = {}     iteration in range(1, iterations + 1):         prob_tree[iteration] = []         # first number represents money in hand, second represents money in pot.     prob_tree[1].append([initial_funds - price_to_play, 1])     iteration in range(2, iterations + 1):         # each possible outcome listed in line above in probability tree         possibility in prob_tree[iteration - 1]:             # if there isn't money in pot , not enough current funds, repeat twice in next line counting purposes.             if possibility[0] < price_to_play , possibility[1] == 0:                 prob_tree[iteration].append(possibility)                 prob_tree[iteration].append(possibility)                 # add current possibility combo twice current iteration.             # elif there money in pot, append heads , tails possibility current row             elif possibility[0] < price_to_play , possibility[1] > 0:                 case2_old_pot = possibility[1]                 case2_win_new_pot = possibility[1] * 2                 case2_lose_new_pot = 0                 case2_player_funds = possibility[0]                 # if successful, money in pot double, , player's money remain constant                 prob_tree[iteration].append([case2_player_funds, case2_win_new_pot])                 # if not successful, money in pot added player's money, , pot return 0                 prob_tree[iteration].append([case2_player_funds + case2_old_pot, case2_lose_new_pot])             # elif there no money in pot there sufficient money in player's pocket play again1             elif possibility[0] >= price_to_play , possibility[1] == 0:                 # first, money in player's pocket goes down amount price_to_play, , pot amount goes one.                 case3_funds_after_buyin = possibility[0] - price_to_play                 case3_pot_after_buyin = 1                 case3_pot_if_successful = 2                 case3_pot_if_unsuccessful = 0                 case3_funds_if_successful = case3_funds_after_buyin                 case3_funds_if_unsuccessful = case3_funds_after_buyin + case3_pot_after_buyin                 # then, either player gets pot , goes 0                 prob_tree[iteration].append([case3_funds_if_unsuccessful, case3_pot_if_unsuccessful])                 prob_tree[iteration].append([case3_funds_if_successful, case3_pot_if_successful])     counter = 0     outcome in prob_tree[iterations]:         if outcome[0] < price_to_play , outcome[1] == 0:             counter += 1     print float(counter)/(2**iterations)  play_game(2, 2, 25) 

i figured number of layers on tree grew larger, answer increasingly accurate. when testing theory, surprised see failure rate 2 pound cost , 2 pound initial amount stabilizing around 35.4%, instead of expected 25.2% problem gives me.

some possible reasons assuming non-failures @ given line go on forever, don't know how account without adding branch , repeating problem. insights appreciated.

for p2(2), pay 2 game starting wealth of 2, use kind-of gradient descent method reach answer given example.

l={x:1.0/2**27 x in range(1,31)} l[1]=1 l[28]=(2.0/3)**27 l[29]=(2.0/3)**28 l[30]=(2.0/3)**29  count = 1 while count <1000:     in range(2,28):         = 4         l[i] =2.0/3*l[i-1]         index = 1         while i-2+a <= 30:             l[i] += 1.0/(2**index * 3)*l[i-2+a]             index += 1             = 2**(index+1)     count +=1     if count % 10 == 0: print 1-l[2] 

it can seen answer converges quickly. gives answer p2(5). large starting wealth, method not


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -