{"id":390,"date":"2007-03-15T12:13:27","date_gmt":"2007-03-15T17:13:27","guid":{"rendered":"http:\/\/ywwg.com\/wordpress\/?p=390"},"modified":"2007-03-15T15:32:01","modified_gmt":"2007-03-15T20:32:01","slug":"march-madness-nerd-style","status":"publish","type":"post","link":"https:\/\/ywwg.com\/wordpress\/archives\/390","title":{"rendered":"March Madness &#8212; nerd style"},"content":{"rendered":"<p>My work is doing a silly contest around the whole NCAA thing.  Back in high school kids used to run around comparing their brackets and arguing over every detail, and I hated it.  I don&#8217;t follow basketball at all, and other than knowing that Duke ususally does well I have no basis upon which to make any choices except the seeds.<\/p>\n<p>So I decided to write a bracket-generating algorithm that uses the seeds to generate weights for a random function and pick teams that way.  The algorithm works as such:<\/p>\n<ul>\n<li>for a pair of teams, take their seeds and invert them (make small numbers big)<\/li>\n<li>divide each seed by the total of the two seeds to get values 0 &lt; = x &lt;= 1<\/li>\n<li>get a random number 0 &lt; = r &lt;= 1.  If team a&#8217;s chance is &gt;= that value, they win<\/li>\n<\/ul>\n<p>The actual code isn&#8217;t as nice as that explanation, but it should be mathematically equivalent.  Any errors in programming only make these results more my own.  I took the results from the first run that (a) worked, and (b) had Wisconsin (my alma mater) not getting knocked out in the first round.<\/p>\n<p>Based on brackets.py, the final four will be: Arizona, Kansas, Texas, and Ohio St.<\/p>\n<p>Kansas will win.<\/p>\n<p>Source code after the break:<br \/>\n<!--more--><\/p>\n<pre>#!\/usr\/bin\/python\r\n\r\nimport random\r\n\r\nMAX_SEED=16.0\r\n\r\ninitial_bracket_1 = [\r\n\t(\"Florida\", 1.0),\r\n\t(\"Jackson St\", 16.0),\r\n\t(\"Arizona\", 8.0),\r\n\t(\"Purdue\", 9.0),\r\n\t(\"Butler\", 5.0),\r\n\t(\"Old Dominion\", 12.0),\r\n\t(\"Maryland\", 4.0),\r\n\t(\"Davidson\", 13.0),\r\n\t(\"Notre Dame\", 6.0),\r\n\t(\"Winthrop\", 11.0),\r\n\t(\"Oregon\", 3.0),\r\n\t(\"Miami (Ohio)\", 14.0),\r\n\t(\"UNLV\", 7.0),\r\n\t(\"Georgia Tech\", 10.0),\r\n\t(\"Wisconsin\", 2.0),\r\n\t(\"Texas A&M CC\", 15.0)\r\n\t]\r\n\t\r\ninitial_bracket_2 = [\r\n\t(\"Kansas\", 1),\r\n\t(\"BY\", 16),\r\n\t(\"Kentucky\", 8),\r\n\t(\"Villanoba\", 9),\r\n\t(\"Virginia Tech\", 5),\r\n\t(\"Illinois\", 12),\r\n\t(\"Southern Ill\", 4),\r\n\t(\"Holy Cross\", 13),\r\n\t(\"Duke\", 6),\r\n\t(\"VCU\", 11),\r\n\t(\"Pittsburgh\", 3),\r\n\t(\"Wright St.\", 14),\r\n\t(\"Indiana\", 7),\r\n\t(\"Gonzaga\", 10),\r\n\t(\"UCLA\", 2),\r\n\t(\"Weber St.\", 15)\r\n\t]\r\n\t\r\ninitial_bracket_3 = [\r\n\t(\"North Carolina\", 1),\r\n\t(\"Eastern Ky.\", 16),\r\n\t(\"Marquette\", 8),\r\n\t(\"Michigan St.\", 9),\r\n\t(\"Southern Cal.\", 5),\r\n\t(\"Arkansas\", 12),\r\n\t(\"Texas\", 4),\r\n\t(\"New Mexico St\", 13),\r\n\t(\"Vanderbilt\", 6),\r\n\t(\"G. Washington\", 11),\r\n\t(\"Washington St.\", 3),\r\n\t(\"Oral Roberts\", 14),\r\n\t(\"Boston College\", 7),\r\n\t(\"Texas Tech\", 10),\r\n\t(\"Georgetown\", 2),\r\n\t(\"Belmont\", 15)\r\n\t]\r\n\t\r\ninitial_bracket_4 = [\r\n\t(\"Ohio St.\", 1),\r\n\t(\"C. Conn. St\", 16),\r\n\t(\"BYU\", 8),\r\n\t(\"Xavier\", 9),\r\n\t(\"Tennessee\", 5),\r\n\t(\"Long Beach\", 12),\r\n\t(\"Virginia\", 4),\r\n\t(\"Albany\", 13),\r\n\t(\"Louisville\", 6),\r\n\t(\"Stanford\", 11),\r\n\t(\"Texas A&M\", 3),\r\n\t(\"Penn\", 14),\r\n\t(\"Nevada\", 7),\r\n\t(\"Creighton\", 10),\r\n\t(\"Memphis\", 2),\r\n\t(\"North Texas\", 15)\r\n\t]\r\n\r\n\t\r\ndef play_bracket(bracket):\r\n\r\n\t\"\"\"returns winners\"\"\"\r\n\t\r\n\twinners = []\r\n\t\r\n\tfor i in range(0, len(bracket), 2):\r\n\t\tteam_a, seed_a = bracket[i]\r\n\t\tteam_b, seed_b = bracket[i+1]\r\n\t\t\r\n\t\tif team_a == \"BY\":\r\n\t\t\twinners.append((team_b, seed_b))\r\n\t\t\tcontinue\r\n\t\telif team_b == \"BY\":\r\n\t\t\twinners.append((team_a, seed_a))\r\n\t\t\tcontinue\r\n\t\t\r\n\t\tadj_seed_a = MAX_SEED - seed_a + 1\r\n\t\tadj_seed_b = MAX_SEED - seed_b + 1\r\n\t\t\r\n\t\tchance_a = adj_seed_a \/ MAX_SEED\r\n\t\tchance_b = adj_seed_b \/ MAX_SEED\r\n\t\t\r\n\t\ttotal = chance_a + chance_b\r\n\t\tchance_a = chance_a \/ total\r\n\t\tchance_b = chance_b \/ total\r\n\t\t\r\n\t\twinner = random.random()\r\n\t\tif winner < = chance_a:\r\n\t\t\twinners.append((team_a, seed_a))\r\n\t\telse:\r\n\t\t\twinners.append((team_b, seed_b))\r\n\t\r\n\treturn winners\r\n\t\r\ndef print_teams(bracket):\r\n\tfor team, seed in bracket:\r\n\t\tprint team\r\n\tprint \"-\"*20\r\n\t\r\ndef play_branch(bracket):\r\n\twhile len(bracket) > 1:\r\n\t\tprint_teams(bracket)\r\n\t\tbracket = play_bracket(bracket)\r\n\tprint bracket[0][0]\r\n\tprint \"=\"*20\r\n\treturn bracket[0]\r\n\t\r\nfinal_four = []\t\r\n\t\r\nfinal_four.append(play_branch(initial_bracket_1))\r\nfinal_four.append(play_branch(initial_bracket_2))\r\nfinal_four.append(play_branch(initial_bracket_3))\r\nfinal_four.append(play_branch(initial_bracket_4))\r\n\r\nplay_branch(final_four)\r\n <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My work is doing a silly contest around the whole NCAA thing. Back in high school kids used to run around comparing their brackets and arguing over every detail, and I hated it. I don&#8217;t follow basketball at all, and other than knowing that Duke ususally does well I have no basis upon which to &hellip; <a href=\"https:\/\/ywwg.com\/wordpress\/archives\/390\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;March Madness &#8212; nerd style&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,23,26,5],"tags":[],"_links":{"self":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/390"}],"collection":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":0,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ywwg.com\/wordpress\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}