{"id":12183,"date":"2014-01-12T14:54:06","date_gmt":"2014-01-12T20:54:06","guid":{"rendered":"http:\/\/bucktownbell.com\/?p=12183"},"modified":"2014-01-12T23:03:24","modified_gmt":"2014-01-13T05:03:24","slug":"xkcd-1313-regex-golf","status":"publish","type":"post","link":"http:\/\/bucktownbell.com\/?p=12183","title":{"rendered":"xkcd 1313: Regex Golf"},"content":{"rendered":"<blockquote><p>I found that the hover text, &#8220;<span style=\"background-color: #ffff99;\">\/bu|[rn]t|[coy]e|[mtg]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls\/ matches the last names of elected US presidents but not their opponents.<\/span>&#8220;, contains a confusing contradiction. There are several last names (like &#8220;Nixon&#8221;) that denote both elected presidents and opponents. So no regular expression could both match and not match &#8220;Nixon&#8221;. I could only assume that Randall meant for these names to be winners and not losers (and in fact he later confirmed that was the correct interpretation).<\/p>\n<p>So that got me thinking: can I come up with an algorithm to find a short regex that covers the winners and not the losers?<\/p>\n<p>I started by finding <a href=\"http:\/\/www.anesi.com\/presname.htm\">a page<\/a> that lists winners and losers of US presidential elections through 2000. Adding the 2004-2012 results I get:\u00a0 &#8230;<\/p><\/blockquote>\n<p>via\u00a0 <a href=\"http:\/\/nbviewer.ipython.org\/url\/norvig.com\/ipython\/xkcd1313.ipynb\">xkcd 1313: Regex Golf<\/a><\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/imgs.xkcd.com\/comics\/regex_golf.png \" \/><\/p>\n<p>Apparently there is a <a href=\"http:\/\/regex.alf.nu\/\">Regex Golf game.<\/a><\/p>\n<blockquote><p>Type a regex in the box. You get ten points per correct match. Hit Enter to go to the next &#8216;level&#8217;.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I found that the hover text, &#8220;\/bu|[rn]t|[coy]e|[mtg]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls\/ matches the last names of elected US presidents but not their opponents.&#8220;, contains a confusing contradiction. There are several last names (like &#8220;Nixon&#8221;) that denote both elected presidents and opponents. So no regular &hellip; <a href=\"http:\/\/bucktownbell.com\/?p=12183\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[54],"tags":[670,557,596,185],"class_list":["post-12183","post","type-post","status-publish","format-standard","hentry","category-programming","tag-algorithms","tag-python","tag-regexp","tag-wtf"],"_links":{"self":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12183"}],"version-history":[{"count":5,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12183\/revisions"}],"predecessor-version":[{"id":12208,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12183\/revisions\/12208"}],"wp:attachment":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12183"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}