Found it. The trick is you have left with some money when you can not afford to make a bet
Exactly.
I was thinking that you either double-up or bust, but what mostly happens is that you end up with something left, but not enough to make the next bet.
Updated the simulation to track the amount you have left when you "lose", and to show the average amount you end up with:
#!/usr/bin/env python
import random, string
start = 15 # starting bankroll
target = 30 # target bankroll
base = 1 # starting bet
rounds = wins = 0
final={}
while True:
bankroll = start
bet = base
rounds += 1
while True:
if random.random() < 0.5: # we won
bankroll += bet # award winnings
bet = base # reset
if bankroll >= target: # we reached the target
wins += 1
break
else: # we lost
bankroll -= bet # subtract loss
bet *= 2 # double bet
if bet > bankroll: # we can't afford the next bet
break
if final.has_key(bankroll):
final[bankroll] += 1
else:
final[bankroll] = 1
if not rounds % 100000:
sum = 0.0
for bankroll in final:
sum += final[bankroll] * bankroll
print "%6d wins out of %6d rounds (%6.3f%%)" % (wins, rounds, wins * 100.0 / rounds)
print string.join(map(lambda(bankroll): "%d:%.2f%%" % (bankroll, final[bankroll] * 100.0 / rounds), final), ', ')
print "expectation: %s" % (sum / rounds)
print
And its output:
3041169 wins out of 8000000 rounds (38.015%)
0:6.24%, 1:5.86%, 2:5.49%, 3:5.13%, 4:4.82%, 5:4.54%, 6:4.24%, 7:3.98%, 8:3.73%, 9:3.50%, 10:3.27%, 11:3.06%, 12:2.87%, 13:2.71%, 14:2.54%, 30:38.01%
expectation: 15.008940625
So only 6.24% of the time do you actually bust.
5.86% of the time you end up with 1 unit,
5.49% of the time, 2 units, etc.
You sometimes has as much as 14 units left, but need to bet 15 to continue, and so count it as a loss.
Not that the average amount you end up with is 15 units - the same as you started with.
What's your Just-Dice userid?