| zeemjr ( @ 2008-04-16 11:13:00 |
Follow Up to Post on Baseball Series (Warning: Technical Content)
I wrote a brief program in C# to answer the question,
4. In baseball, suppose the American League champion is better than the National League champion, such that it has a 55% probability of winning each game against the NL champ. Then the NL champ nonetheless will win a best-of-seven-games series four in 10 times. What is the smallest odd number, X, for which a World Series between these two league champs that is best-of-X will ensure that there’s a 95% probability of a just result — the superior AL champ winning?
Consider a 5-game series. A team can sweep in three games. To win in four games, the victor can lose only one of the first three. That means there are three distinct win-loss sequences that result in a team winning in four games.
In general to choose k items (in this case wins) from a group of n (games):
n choose k = n!/(k! * (n - k)!) {Note: x! is the product of all the integers from x to 1, so 5! = 5*4*3*2*1 = 120}
Google will actually do this for you, typing 5 choose 3 in the search line returns the answer 10.
So I figured out the chances a team would win a series in each number of games, and then added them.
Here is my code:
namespace Project40708
{
class Program
{
static void Main(string[] args)
{
int x = 3; //The shortest non-trivial series
double prob;
do
{
prob = 0;
for (int i = (x - 1) / 2; i < x; i++)// This loop starts out at the earliest point which a team can win a series.
{
prob = prob + step(i, (x - 1) / 2);// accumulates the chances of winning in exactly i games
}
Console.WriteLine("The AL team wins a best of {0} series with probability {1}", x, prob);
x = x + 2;// The series are best of x, x is always odd.
}
while (prob < .950);
}
static double step (int x, int y)
{
if (y > x)
return 0;
double result = 0;
if (y == x)
{
return Math.Pow(.55, y + 1);//This is a sweep!
}
result = step(x - 1, y) * x / (x - y) * .45;//I did this recursively.
return result;
}
}
}
I wrote a brief program in C# to answer the question,
4. In baseball, suppose the American League champion is better than the National League champion, such that it has a 55% probability of winning each game against the NL champ. Then the NL champ nonetheless will win a best-of-seven-games series four in 10 times. What is the smallest odd number, X, for which a World Series between these two league champs that is best-of-X will ensure that there’s a 95% probability of a just result — the superior AL champ winning?
Consider a 5-game series. A team can sweep in three games. To win in four games, the victor can lose only one of the first three. That means there are three distinct win-loss sequences that result in a team winning in four games.
In general to choose k items (in this case wins) from a group of n (games):
n choose k = n!/(k! * (n - k)!) {Note: x! is the product of all the integers from x to 1, so 5! = 5*4*3*2*1 = 120}
Google will actually do this for you, typing 5 choose 3 in the search line returns the answer 10.
So I figured out the chances a team would win a series in each number of games, and then added them.
Here is my code:
namespace Project40708
{
class Program
{
static void Main(string[] args)
{
int x = 3; //The shortest non-trivial series
double prob;
do
{
prob = 0;
for (int i = (x - 1) / 2; i < x; i++)// This loop starts out at the earliest point which a team can win a series.
{
prob = prob + step(i, (x - 1) / 2);// accumulates the chances of winning in exactly i games
}
Console.WriteLine("The AL team wins a best of {0} series with probability {1}", x, prob);
x = x + 2;// The series are best of x, x is always odd.
}
while (prob < .950);
}
static double step (int x, int y)
{
if (y > x)
return 0;
double result = 0;
if (y == x)
{
return Math.Pow(.55, y + 1);//This is a sweep!
}
result = step(x - 1, y) * x / (x - y) * .45;//I did this recursively.
return result;
}
}
}