News for hackers. Stuff that matters.
Re:Show HN: March Madness for Hackers by trg2 on Monday March 17, 2014 @02:10PM (#7416874)
This is awesome! I went to UConn, so I'll obviously hard-code a UConn win there. But I heard on NPR today that, historically, a 12 seed has a 50% chance of upsetting a 5 seed in the first round. If I'm biasing towards the higher seeds everywhere else, that means my code looks like this:

function (game, team1, team2) {

  var winner_team = "Connecticut";
  
  if (team1.name == winner_team) {
    team1.winsGame();
  } else if (team2.name == winner_team) {
    team2.winsGame();
  } else if (team1.seed > team2.seed) {
    team2.winsGame();
  } else if (team2.seed == "12") {
    team2.winsGame();
  } else {
    team1.winsGame();
  }
            
}
Re:Show HN: March Madness for Hackers by selectout on Monday March 17, 2014 @04:19PM (#7417800)
WOuldn't this not take into account 12 seeds winning? Since you do team1.seed > team2.seed before checking if team2.seed is 12.

Also, this would mean 12 seeds would go all the way anyway, you're not limiting it to the first round only.

Re:Show HN: March Madness for Hackers by shazeline on Monday March 17, 2014 @10:38PM (#7419683)
Yeah, trg2 would need to put all the edge case rules towards the beginning. That, or just put the basic rules at the beginning and have separate conditionals at the end to handle the edge cases.
Re:Show HN: March Madness for Hackers by trg2 on Tuesday March 18, 2014 @10:21AM (#7422054)
Good call - thanks for the CR! :)
Re:Show HN: March Madness for Hackers by dy on Monday March 17, 2014 @03:02PM (#7417267)
This is exactly the reason we built this - it's much harder to keep all these various rules in your head while you're making your bracket, but simple to execute in code. Thanks for the awesome example!