Guest User

Untitled

a guest
Aug 2nd, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. import random
  2.  
  3. GREEN = "GREEN"
  4. RED = "RED"
  5. BLACK = "BLACK"
  6. slots = [GREEN] + [RED, BLACK] * 18
  7.  
  8. # bet constant k dollars each round and stop playing once my profit is k dollars.
  9. TARGET_AMOUNT = 1
  10. BET_AMOUNT = 1
  11.  
  12. def i_play_atmost_N_spins_each_day(N = 1000):
  13.     net_amount = 0
  14.     most_loss = 0 # expected bankroll. i.e i should expect this much to lose in the worst case.
  15.    
  16.     previous_outcome = RED
  17.     i = 0
  18.     for _ in range(1,N+1):
  19.         i += 1
  20.         outcome = random.choice(slots) # spin the roulette wheel.
  21.         if(outcome == previous_outcome): # always bet on the previous outcome.
  22.             net_amount += BET_AMOUNT
  23.         else:
  24.             net_amount -= BET_AMOUNT
  25.  
  26.         most_loss = min(most_loss, net_amount)
  27.    
  28.         if(net_amount == TARGET): # stop playing once I profit 1$
  29.             break
  30.         previous_outcome = outcome
  31.         if(previous_outcome == GREEN):
  32.             previous_outcome = RED
  33.  
  34.     return (i,most_loss,net_amount) # save a record of total_spins, most_negative_i_went, net_amount_at_the_end
  35.  
  36.  
  37.  
  38.  
  39. spins_i_played_each_day = [] # maximum is N spins.
  40. most_negative_i_went_each_day = []
  41. net_amount_i_have_each_day = []
  42.  
  43. i_profited_these_many_days = 0
  44. i_go_casino_these_many_days = 365
  45.  
  46. for _ in range(i_go_casino_these_many_days):
  47.     total_spins_that_day, most_loss_that_day, net_amount_that_day = i_play_atmost_N_spins_each_day()
  48.  
  49.     if(net_amount_that_day == TARGET):
  50.         i_profited_these_many_days += 1
  51.     spins_i_played_each_day.append(total_spins_that_day)
  52.     most_negative_i_went_each_day.append(most_loss_that_day)
  53.     net_amount_i_have_each_day.append(net_amount_that_day)
  54.  
  55. print(i_profited_these_many_days/i_go_casino_these_many_days) # output: between 0.89 ~ 0.91
  56. print(min(most_negative_i_went_each_day)) # output: between 80 ~ 140
Add Comment
Please, Sign In to add comment