I wrote up a quick version of this in python (assuming I read it right).<p>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&#x27;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.<p>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.<p><pre><code>  #!&#x2F;usr&#x2F;bin&#x2F;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(&quot;Round: {}, win: {}, Max win: {}, profit: {}, Breakeven cost: {:0.2f}&quot;.format(i, win, max_win, profit, profit&#x2F;i))
      return profit&#x2F;i
  
  def avg(l):
      return sum(l) &#x2F; len(l)
  
  def main():
      breakevens = []
      for _ in range(1000):
          be = simulate()
          breakevens.append(be)
  
      print(&quot;Lowest breakeven cost: {:0.2f}&quot;.format(min(breakevens)))
      print(&quot;Average breakeven cost: {:0.2f}&quot;.format(avg(breakevens)))
      print(&quot;Highest breakeven cost: {:0.2f}&quot;.format(max(breakevens)))
  
  if __name__ == &quot;__main__&quot;:
      main()</code></pre>