{"id":4472,"date":"2017-03-10T18:12:27","date_gmt":"2017-03-10T23:12:27","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=4472"},"modified":"2018-08-07T15:40:04","modified_gmt":"2018-08-07T19:40:04","slug":"results-of-the-st-andrews-programming-contest","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2017\/03\/10\/results-of-the-st-andrews-programming-contest\/","title":{"rendered":"Results of the St Andrews Programming Contest"},"content":{"rendered":"<p>Last month we collaborated with Luke Rendell and Elena Miu of St Andrews University on a programming contest (hosted at <a href=\"http:\/\/cumuluscontest.org\/current-contest\">CumulusContest.org<\/a>). This contest was modeled on\u00a0our old MATLAB programming contest.<\/p>\n<p>My job was to come up with a challenge. Here it is:\u00a0take a chain and coil it on the floor of a box. For instance, suppose I gave you this chain. Each link, or bead, is drawn a different size to indicate that it has a different weight.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"413\" height=\"76\" class=\"alignnone size-full wp-image-4478\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/bb52c7db487bcc97c7d3e58e485201e6.png\" alt=\"\" \/><br \/>\nYour job is to place the chain in the box compactly; that is, with the heavy bits bunched in the middle as much as possible. Even so, the chain must lie in a single plane and snake through the box using only straight segments or 90 degree turns.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"380\" height=\"260\" class=\"alignnone size-full wp-image-4479\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/a528353730a0d561d7f9a03972bccacb.png\" alt=\"\" \/><\/p>\n<p>Here&#8217;s an example built with MATLAB code. How would you arrange this chain?<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"338\" height=\"77\" class=\"alignnone size-full wp-image-4481\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads1.png\" alt=\"\" \/><br \/>\nYou can see easily enough that we want to put the heaviest weight right in the middle. So the optimal weight distribution looks like this.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"355\" height=\"358\" class=\"alignnone size-full wp-image-4482\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads1-answer.png\" alt=\"\" \/><\/p>\n<p>But now suppose you were given this chain. It&#8217;s the same weights, but in a different order.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"338\" height=\"77\" class=\"alignnone size-full wp-image-4483\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads1-1.png\" alt=\"\" \/><\/p>\n<p>The optimal weight distribution is the same, but the snaking path of the chain is different.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"343\" height=\"343\" class=\"alignnone size-full wp-image-4484\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads2-answer.png\" alt=\"\" \/><\/p>\n<p>So you get the basic idea. But the problem gets much harder to solve as the chain gets longer. Given this chain, how would you write an algorithm to fold it quickly and efficiently?<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"341\" height=\"344\" class=\"alignnone size-full wp-image-4485\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads3.png\" alt=\"\" \/><\/p>\n<p>Here&#8217;s what the winner of the contest generated. Not bad!<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"334\" height=\"336\" class=\"alignnone size-full wp-image-4486\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads2-answer2.png\" alt=\"\" \/><br \/>\nIt&#8217;s a fiendish problem. Participants of the contest couldn&#8217;t afford to test their answers exhaustively. For one thing, combinatorics being what they are, there isn&#8217;t enough time in the universe to be completely exhaustive. For another thing, we gave them only 50 seconds to solve more than 100 of these problems.<\/p>\n<p>I&#8217;m so impressed with the people who coded up solutions. Not just solutions, but lots of them, and lots of good ones. And they&#8217;re all available for your inspection on the site. Here is a plot of all the entries.\u00a0There were\u00a01148 total entries, of which 841 passed and received scores. Among these passing entries were 89 leaders.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"486\" height=\"396\" class=\"alignnone size-full wp-image-4473\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/score-v-time.png\" alt=\"\" \/><\/p>\n<p>That red line running along the bottom goes through each of the leaders. The algorithms started out small, but they grew as the contest progressed. Here&#8217;s a plot of code size over time.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"501\" height=\"401\" class=\"alignnone size-full wp-image-4490\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/code-len.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ll finish with an animation of an especially entertaining kind of chain:\u00a0a collection of equal weights separated by long empty stretches of cable. It made for some beautiful maze-like results. Here&#8217;s the starting chain. How would you cluster those beads in the middle?<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"286\" height=\"285\" class=\"alignnone size-full wp-image-4487\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/beads4.png\" alt=\"\" \/><\/p>\n<p>Below is an animation of the results achieved by 24 different leading algorithms. I&#8217;m not showing all the leaders because many of them were speed improvements that didn&#8217;t change the layout of the chain.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"372\" height=\"317\" class=\"alignnone size-full wp-image-4475\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/leaders-animation.gif\" alt=\"\" \/><\/p>\n<p>Stay tuned&#8230; I understand the folks at St Andrews want to run more contests! When they do, I&#8217;m sure they&#8217;ll announce it over on their <a href=\"http:\/\/cumuluscontest.org\/\">CumulusContest<\/a>\u00a0site.<\/p>\n<p>And as always, thanks to everyone who played!<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/community\/files\/a528353730a0d561d7f9a03972bccacb.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Last month we collaborated with Luke Rendell and Elena Miu of St Andrews University on a programming contest (hosted at CumulusContest.org). This contest was modeled on\u00a0our old MATLAB programming&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2017\/03\/10\/results-of-the-st-andrews-programming-contest\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":4479,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4472"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=4472"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4472\/revisions"}],"predecessor-version":[{"id":4492,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/4472\/revisions\/4492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media\/4479"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=4472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=4472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=4472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}