Blogs
NCAA bracket C# source code results
Submitted by Blake on Mon, 04/13/2009 - 12:34Just about a month ago, I posted some C# source code about making picks for an NCAA bracket. The code is basically broken into 3 parts:
- Retrieving all team information from a config file.
- For each match-up between two teams, pick the winner given an algorithm.
- Display the result bracket.
The code was built to be modular enough so that any step could be expanded upon at a later date. The most obvious step that needs building is (2). The code as it is now only looks at the two teams' ranks - though it doesn't just take the lower rank (it's random but favors the lower rank), but still.
Anyways, now that the entire championship is complete and all the results are out there, I can run it a few more times and see how the bracket generator holds up when compared against the actual winners. Given that in most NCAA pools, the Final Four and on is really what it comes down to, I figured I would just run the program N times and check the following: 1) Did it nail all four teams in the Final Four? 2) The two teams in the finals? 3) The final winner.
Instead of using another config file, I just quickly built the final four, finals, and champion data manually in the code:
private List GetWinners()
{
Team mich = new Team("Michigan State", 2);
Team conn = new Team("Connecticut", 1);
Team vill = new Team("Villanova", 3);
Team nc = new Team("North Carolina", 1);
Round four = new Round();
four.Teams.Add(mich);
four.Teams.Add(conn);
four.Teams.Add(vill);
four.Teams.Add(nc);
Round two = new Round();
two.Teams.Add(mich);
two.Teams.Add(nc);
Round one = new Round();
one.Teams.Add(nc);
List winners = new List();
winners.Add(four);
winners.Add(two);
winners.Add(one);
return winners;
}
Here's the code for checking if one set of teams is equal to another set, i.e. if the teams in my Final Four picks match the actual Final Four results:
private bool RoundsEqual(Round r1, Round r2)
{
int equalCount = 0;
foreach (Team t1 in r1.Teams)
{
foreach (Team t2 in r2.Teams)
{
if (String.Compare(t1.Name, t2.Name, true) == 0)
{
equalCount++;
break;
}
}
}
return (equalCount == r1.Teams.Count);
}
One more quick thing. I moved all the code from last week into one class: BracketProcessor. For the last entry, all the code was just in the page CreateBracket.aspx. But now I wanted a new page BracketResultsReport.aspx. So I moved into all into a separate object, called that from both pages, left the method DisplayBracket on CreateBracket, and included this new code on the BracketResultsReport page. The code from last post is all the same; only change is that I made sure that the GetFirstRound method is only called once, since on the new page, it would be called several times.
With all that in place, the rest of the code is pretty straightforward:
private const int TEST_COUNT = 1000000;
protected void Page_Load(object sender, EventArgs e)
{
BracketProcessor processor = new BracketProcessor();
List winners = GetWinners();
int[] correctCounts = new int[] { 0, 0, 0 };
for (int i = 0; i < TEST_COUNT; i++)
{
List rounds = processor.BuildBracket();
int roundOffset = rounds.Count - 3;
for (int j = 0; j < 3; j++)
{
if (RoundsEqual(winners[j], rounds[j + roundOffset]))
correctCounts[j]++;
}
}
Response.Write(String.Format("Total tests: {0}
", TEST_COUNT.ToString()));
Response.Write(String.Format("Final Four: {0}
", correctCounts[0].ToString()));
Response.Write(String.Format("Finals: {0}
", correctCounts[1].ToString()));
Response.Write(String.Format("Winner: {0}", correctCounts[2].ToString()));
}
I double-checked this would work, then set the count up to a million. I ran it a few times and got pretty consistent results:
Total tests: 1000000
Final Four: 6238
Finals: 31904
Winner: 185449
Total tests: 1000000
Final Four: 6252
Finals: 32005
Winner: 185466
Total tests: 1000000
Final Four: 6225
Finals: 32114
Winner: 185839
With percents, that's roughly:
Final Four: 0.6%
Finals: 3.2%
Winner: 18.5%
Not too shabby, especially with an admittedly rudimentary algorithm to pick a winner. That's about 1 in 5 for picking the winner. With the structure in place, the PickWinner method could be beefed up to take in more stats, including further results of this NCAA championship.
"A big day" because of the Best Week Ever
Submitted by Blake on Tue, 04/07/2009 - 17:56Well, we had some excitement last week. For a youtube video to be popular, sometimes it takes personal determination such as, say, submitting your youtube in a contest. Other times, however, it's up to random chance. A writer of a popular web site clicks around youtube on a hunt for content - possibly to support a point, or simply to provide a collection of entertainment. Darius first felt the bump when his Mantech vid was featured on toplessrobot last April. Most recently, my Blossom Theme Song on ukelele was featured on VH1's Best Week Ever site on a list: 13 Awesome TV Show Theme Song Covers.
Now usually, I'll start to get an idea that a vid has been discovered from comments on the "found" vid. I get email notifications every time there's a new comment on a vid. The notifications are a good wet thumb in the air to detect if the wind's blowing strongly in a certain direction.
Still, not every system is perfect. As a result, I'll check my Insight page, usually every day or so, to see if there are any surprises. And last Wednesday (April 1st as it turns out, yet I never had the thought that youtube was putting one over on me), the Insight report looked promising - a steady slope upwards.
Usually my views per day hover around 200, but this time it was skyrocketing. Given the context of the embed -- One embed out of 13, on a site with several daily updates to keep the highly-stimulated audience's attention -- I figured I would have a classic spike, hitting a peak, then sliding down again.
To a certain degree, that was the behavior: There didn't seem to be a lot of click-throughs to other vids or to this site. However, even after the decline, my mean views per day has been hovering around 400, definitely higher than usual. This may be an indicator that, when you're a potential flash-in-the-pan, you'll experience 1) a lot of buzz 2) a sharp decline 3) a permeating low level of buzz for a length of time 4) a now gradual decline to the previous numbers.
As of now, Blossom is still on the top of the charts for views per day. I'm guessing that'll go down to its previous level, but who knows. Before all this happened, I believe it was was pretty low on the list, possibly not even making the initial Insight list report. It's hard to tell though, it could stay as a contender with Whistle Stop and Charlotte's Web.
Oh, and it did end up getting a few comments, though with some insider help :)
