Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- GREEN = "GREEN"
- RED = "RED"
- BLACK = "BLACK"
- slots = [GREEN] + [RED, BLACK] * 18
- # bet constant k dollars each round and stop playing once my profit is k dollars.
- TARGET_AMOUNT = 1
- BET_AMOUNT = 1
- def i_play_atmost_N_spins_each_day(N = 1000):
- net_amount = 0
- most_loss = 0 # expected bankroll. i.e i should expect this much to lose in the worst case.
- previous_outcome = RED
- i = 0
- for _ in range(1,N+1):
- i += 1
- outcome = random.choice(slots) # spin the roulette wheel.
- if(outcome == previous_outcome): # always bet on the previous outcome.
- net_amount += BET_AMOUNT
- else:
- net_amount -= BET_AMOUNT
- most_loss = min(most_loss, net_amount)
- if(net_amount == TARGET): # stop playing once I profit 1$
- break
- previous_outcome = outcome
- if(previous_outcome == GREEN):
- previous_outcome = RED
- return (i,most_loss,net_amount) # save a record of total_spins, most_negative_i_went, net_amount_at_the_end
- spins_i_played_each_day = [] # maximum is N spins.
- most_negative_i_went_each_day = []
- net_amount_i_have_each_day = []
- i_profited_these_many_days = 0
- i_go_casino_these_many_days = 365
- for _ in range(i_go_casino_these_many_days):
- total_spins_that_day, most_loss_that_day, net_amount_that_day = i_play_atmost_N_spins_each_day()
- if(net_amount_that_day == TARGET):
- i_profited_these_many_days += 1
- spins_i_played_each_day.append(total_spins_that_day)
- most_negative_i_went_each_day.append(most_loss_that_day)
- net_amount_i_have_each_day.append(net_amount_that_day)
- print(i_profited_these_many_days/i_go_casino_these_many_days) # output: between 0.89 ~ 0.91
- print(min(most_negative_i_went_each_day)) # output: between 80 ~ 140
Add Comment
Please, Sign In to add comment