2 ms·
I wrote up a quick version of this in python (assuming I read it right). Rather than try to keep track of profit and loss it just plays for 1000 rounds and fig
by justinsaccount 11y ago
I wrote up a quick version of this in python (assuming I read it right).
Rather than try to keep track of profit and loss it just plays for 1000 rounds and figures out the max cost per game that would have broken even. There's different ways of doing it obviously.. like assign actual values to starting money and cost per game and then play until a 20% profit or bankruptcy.
From what I see for 1000 rounds, paying $6 would mean a profit 100% of the time. Also, average breakeven should probably take the 90th percentile.
#!/usr/bin/env python3
import random
def play():
profit = 2
while True:
if random.choice([0,1]):
return profit
profit *=2
def simulate():
profit = 0
plays = 0
max_win = 0
threshold=10
for i in range(1, 1001):
win = play()
profit += win
max_win = max(win, max_win)
print("Round: {}, win: {}, Max win: {}, profit: {}, Breakeven cost: {:0.2f}".format(i, win, max_win, profit, profit/i))
return profit/i
def avg(l):
return sum(l) / len(l)
def main():
breakevens = []
for _ in range(1000):
be = simulate()
breakevens.append(be)
print("Lowest breakeven cost: {:0.2f}".format(min(breakevens)))
print("Average breakeven cost: {:0.2f}".format(avg(breakevens)))
print("Highest breakeven cost: {:0.2f}".format(max(breakevens)))
if __name__ == "__main__":
main()