Skip to content

Instantly share code, notes, and snippets.

@dandrews
Forked from anonymous/gist:5573439
Created May 15, 2013 02:22
Show Gist options
  • Save dandrews/5581242 to your computer and use it in GitHub Desktop.
Save dandrews/5581242 to your computer and use it in GitHub Desktop.
'''
odds of winning: .5776398
odds of losing: .4223602
odds of winning game after winning 1: 23/34 .67647059
odds of winning game after winning 2: 15/23 .65217391
odds of winning game after winning 3: 9/15 .60000000
odds of winning game after winning 4: 7/9 .77777778
odds of winning game after winning 5: 3/7 .42857143
odds of winning game after winning 6: 2/3 .66666667
odds of winning game after winning 7: 0 .00000000
odds of losing game after losing 1: 17/35 .48571429
odds of losing game after losing 2: 8/17 .47058824
odds of losing game after losing 3: 4/8 .50000000
odds of losing game after losing 4: 1/4 .25000000
odds of losing game after losing 5: 1/1 1.0000000
odds of losing game after losing 6: 1/1 1.0000000
odds of losing game after losing 7: 1/1 1.0000000
odds of losing game after losing 8: 0/1 .000000000
'''
import random
winning_odds=[.5776398,.67647059,.65217391,.6,.77777778,.42857143,.66666667,0]
losing_odds=[.4223602,.48571429,.47058824,.5,.25,1,1,1,0]
streak=['losing',3] #5/12 for current 2013 season
season_record=[21,16]
winning_records=[]
losing_records=[]
def thefunction(start,stop):
for i in range(start,stop):
r=random.randint(1,100)
if streak[0] == 'winning':
if r<(winning_odds[streak[1]]*100):
streak[1]+=1
season_record[0]+=1
else:
streak[0]='losing'
streak[1]=1
season_record[1]+=1
else:
if r<(losing_odds[streak[1]]*100):
if season_record[1]==16: print "lost monday"
streak[1]+=1
season_record[1]+=1
else:
if season_record[0]==21: print "won monday"
streak[0]="winning"
streak[1]=1
season_record[0]+=1
print season_record
winning_records.append(season_record[0])
losing_records.append(season_record[1])
print "---------"
for z in range (1,500):
season_record=[21,16]
thefunction(1,127)
#get average winning record
print reduce(lambda x, y: x + y, winning_records) / float(len(winning_records))
print "---------"
#get average losing record
print reduce(lambda x, y: x + y, losing_records) / float(len(losing_records))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment