Last active
February 3, 2017 10:45
-
-
Save yammesicka/2207a9be64731e33e92d25e025f7fec7 to your computer and use it in GitHub Desktop.
Show that Martingale doesn't work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
NUMBER_OF_ROUNDS = 10000 | |
POT_LIMIT = 500 | |
INITIAL_CASH_IN_HAND = 500 # Dollars | |
IS_ABLE_TO_OVERDRAFT = True | |
NUMBERS_IN_ROULETTE = 36 # 1 will be added to represent 0. | |
STARTING_BET_SIZE = 1 | |
BET_MULTIPLICATION_FACTOR = 2 | |
RED_NUMBERS = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, | |
21, 23, 25, 27, 30, 32, 34, 36] | |
cash_in_hand = INITIAL_CASH_IN_HAND | |
total_money_by_round = [] | |
bet_size = STARTING_BET_SIZE | |
i = 0 | |
while (i < NUMBER_OF_ROUNDS and | |
((cash_in_hand - bet_size > 0) or IS_ABLE_TO_OVERDRAFT)): | |
cash_in_hand -= bet_size | |
number = random.choice(range(NUMBERS_IN_ROULETTE+1)) | |
if number in RED_NUMBERS: | |
cash_in_hand += bet_size * 2 | |
bet_size = STARTING_BET_SIZE | |
else: | |
bet_size *= BET_MULTIPLICATION_FACTOR | |
if bet_size > POT_LIMIT: | |
bet_size = STARTING_BET_SIZE | |
total_money_by_round.append(cash_in_hand) | |
i += 1 | |
plt.plot(range(NUMBER_OF_ROUNDS), total_money_by_round) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment