Untitled
unknown
plain_text
4 years ago
1.4 kB
11
Indexable
# All Imports
import pickle
import termplotlib
import random
# Defining Important Variables
depth = 0
d0 = {"Doubled" : 0, "Bankrupt" : 0}
d1 = {"Doubled" : 0, "Bankrupt" : 0}
d2 = {"Doubled" : 0, "Bankrupt" : 0}
d3 = {"Doubled" : 0, "Bankrupt" : 0}
d4 = {"Doubled" : 0, "Bankrupt" : 0}
d5 = {"Doubled" : 0, "Bankrupt" : 0}
d6 = {"Doubled" : 0, "Bankrupt" : 0}
d7 = {"Doubled" : 0, "Bankrupt" : 0}
d8 = {"Doubled" : 0, "Bankrupt" : 0}
d9 = {"Doubled" : 0, "Bankrupt" : 0}
d10 = {"Doubled" : 0, "Bankrupt" : 0}
initial = 10
bank = 0
runs = 1
sides = ["Heads", "Tails"]
# Defining The Flip Function
def Flip(side, sides):
choice = random.choice(sides)
if choice == side:
return True
else:
return False
# Defining The Martingale Function
def Martingale(depth, initial, bank, runs):
org_bal = bank
bank = initial * pow(2, depth)
current = initial
for run in str(runs):
run = int(run)
if bank == 2 * org_bal:
globals()["d" + str(depth)]["Double"] += 1
elif bank == 0:
globals()["d" + str(depth)]["Bankrupt"] += 1
else:
side = random.choice(sides)
outcome = Flip(side, sides)
if outcome == True:
bank += 2 * current
else:
bank -= current
current = 2 * current
# Defining The Run Function
def Run(initial, bank, runs):
for depth in range(0, 11):
Martingale(depth, initial, bank, runs)
# Testing
Run(initial, bank, runs)
for x in range(0, 11):
x = str(x)
print(globals()["d" + x])
Editor is loading...