Skip to content

Instantly share code, notes, and snippets.

View JeffSackmann's full-sized avatar

Jeff Sackmann JeffSackmann

View GitHub Profile
@JeffSackmann
JeffSackmann / tennisSetProbability.py
Created January 12, 2011 21:58
calculate the probability of the current server winning a 6-game, tiebreak set, given prob. of server winning any given service point (s) or return point (u), and the current game score (v, w)
## calculate the probability of the current server winning
## a 6-game, tiebreak set, given prob. of server winning any
## given service point (s) or return point (u), and the current
## game score (v, w)
## some results:
## http://summerofjeff.wordpress.com/2010/12/02/single-set-win-expectancy-tables/
def fact(x):
if x in [0, 1]: return 1
@JeffSackmann
JeffSackmann / tennisTiebreakProbability.py
Created January 12, 2011 21:02
calculate the probability that the current server wins a p-point tiebreak, given server's probability of winning serve and return points, and the current score.
## calculate the probability that the current server wins a best-of-p tiebreak.
## some results shown here:
## http://summerofjeff.wordpress.com/2010/12/04/7-point-tiebreak-win-expectancy-tables/
def fact(x):
if x in [0, 1]: return 1
r = 1
for a in range(1, (x+1)): r = r*a
return r