Created
October 1, 2016 10:57
-
-
Save dakk/fcd726acb3644ce9418f3b7219620085 to your computer and use it in GitHub Desktop.
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 | |
betRange = [79.0, 81.0] | |
def doBet (bet, winRange, mul): | |
r = random.randint (1, 9999) / 100.0 | |
if r >= winRange[0] and r <= winRange[1]: | |
return bet * mul | |
else: | |
return -bet | |
def testCase1 (jack = 1.0): | |
bal = 0.00500000 | |
base = 0.00000001 | |
current_bet = base | |
n = 0 | |
strike = 0 | |
giveup = 0 | |
won = 0 | |
current_limit = 100 | |
while bal > 0.0 and bal < jack and bal > current_bet: | |
ch = doBet (current_bet, betRange, 49.5) | |
bal += ch | |
if (ch > 0.0): | |
current_bet = base | |
strike = 0 | |
won += 1 | |
else: | |
if strike <= current_limit: | |
current_bet += base | |
strike += 1 | |
else: | |
base = base * 10 | |
current_limit = current_limit * 10 | |
current_bet = base | |
strike = 0 | |
#print bal, strike, giveup, won | |
n += 1 | |
if bal >= jack: | |
return (True,n) | |
else: | |
return (False,n) | |
def testCase2 (jack = 1.0): | |
bal = 0.0100000 | |
base = 0.0000001 | |
current_bet = base | |
n = 0 | |
strike = 0 | |
giveup = 0 | |
won = 0 | |
current_limit = 100 | |
while bal > 0.0 and bal < jack and bal > current_bet: | |
ch = doBet (current_bet, betRange, 49.5) | |
bal += ch | |
if (ch > 0.0): | |
current_bet = base | |
strike = 0 | |
won += 1 | |
else: | |
if strike <= current_limit: | |
current_bet += base | |
strike += 1 | |
else: | |
current_bet = base | |
strike = 0 | |
#print bal, strike, giveup, won | |
n += 1 | |
if bal >= jack: | |
return (True,n) | |
else: | |
return (False,n) | |
totWin = 0 | |
totLos = 0 | |
avgWin = 1.0 | |
avgLos = 1.0 | |
for i in range (0, 1000000): | |
(win,n) = testCase1 (0.1) | |
if win: | |
avgWin = (avgWin + n) / 2 | |
totWin += 1 | |
else: | |
avgLos = (avgLos + n) / 2 | |
totLos += 1 | |
print avgWin, totWin, '\t\t', avgLos, totLos, '\t\t', (float (totWin) / (0.1+float (totLos+totLos)) * 100.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment