{"id":57,"date":"2010-08-07T05:11:58","date_gmt":"2010-08-07T05:11:58","guid":{"rendered":"http:\/\/morganredfield.com\/blog\/?p=57"},"modified":"2022-11-21T01:12:21","modified_gmt":"2022-11-21T01:12:21","slug":"opening-doors","status":"publish","type":"post","link":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/","title":{"rendered":"Opening Doors"},"content":{"rendered":"<p>I ran into an <a href=\"http:\/\/www.mathispretty.com\/?p=314\">interesting math puzzle<\/a> while trawling the blag-o-sphere today.<\/p>\n<blockquote><p>One hundred students line up to walk by one hundred closed lockers. The first student walks by opening every locker that is closed. The second student then walks by and opens every second locker that is closed and closes every second locker that is open. The third student does the same for every third locker and the nth student does the same for every nth locker.<\/p>\n<p>After all the students have walked by the lockers, how many lockers are open?<\/p><\/blockquote>\n<p>I thought about this for a while, but I was having some trouble visualizing what was happening. In the end, I decided to graph it to see what was happening. I wrote up a quick Processing sketch and looked at a smaller version of the problem. My smaller version had only ten lockers and ten people who run through them.<\/p>\n<p><a href=\"https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-63\" title=\"Timeline of ten lockers\" src=\"https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\" alt=\"Timeline of ten lockers being toggled\" width=\"155\" height=\"300\" \/><\/a><\/p>\n<p>Once you&#8217;re looking at the picture, the answer the question is obvious. I&#8217;m not very satisfied with this method of solving the problem. It seems inelegant, and is purely a brute-force approach.<\/p>\n<p>Another way to approach the problem is see if there is a closed form solution for any given door. If we had that, we could solve for the state of each locker and sum them up. Unfortunately, I think this comes down to a factoring problem. If the locker number has an even number of factors, then it is closed. If it has an odd number of factors, it is open. Interestingly, since most of the lockers remain closed it seems that most numbers have an even number of unique factors. That doesn&#8217;t really help explain the problem though.<\/p>\n<p><a href=\"https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/solns_upto_16lockers.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-62\" title=\"Solutions upto 16 Lockers\" src=\"https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/solns_upto_16lockers-163x300.jpg\" alt=\"Solutions upto 16 Lockers\" width=\"163\" height=\"300\" srcset=\"https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/solns_upto_16lockers-163x300.jpg 163w, https:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/solns_upto_16lockers.jpg 245w\" sizes=\"auto, (max-width: 163px) 85vw, 163px\" \/><\/a><\/p>\n<p>So if I can&#8217;t find a closed form solution to the state of each locker, what other patterns can I see? By looking at the solutions for different numbers of lockers, I see that total number of lockers needed to give a certain number of opens follows some kind of power function. Looking at the first sixteen solutions shows that if I want n open lockers, then I need 2^n total lockers.<\/p>\n<p>This is more like it. Now when someones asks about 100 lockers, I can find a solution quickly. What squared is 100? It&#8217;s 10 of course, so there are 10 open lockers after this sequence of events has been applied to 100 lockers. For any number, n, of lockers, the number of open lockers after n people have run though them is ?n rounded down.<\/p>\n<p>So now I have my answer. I just need a reason. Why is it the case that the open doors follow this pattern? What that really boils down to after looking at it for a bit is the question: why are the only doors left open doors that are the square of a number? Does this mean that only square numbers have an odd number of unique factors?<\/p>\n<p>Square numbers are the only numbers that have an odd number of unique factors because factors can come in pairs. With a square number, one of those pairs is made up of two of the same number, and in this situation that can only count as one toggle, not two.<\/p>\n<p>So take locker number 10 for example. It has factors 1, 2, 5, 10. In this case 1 goes with 10 and 5 goes with 2. They cancel each other out and the locker stays closed.<\/p>\n<p>The number 9, on the other hand, has factors 1, 3, 9. Here the 1 and the 9 cancel each other out, but the 3 doesn&#8217;t have anything to cancel it out. The locker remains open.<\/p>\n<p>It turns out that getting sidetracked about closed form solutions for each individual door actually did provide the hint to understanding the problem.<\/p>\n<p>You can <a href=\"https:\/\/github.com\/mogar\/PuzzleViz\/tree\/main\/locker_puzzle\">get the code I used for my images here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into an interesting math puzzle while trawling the blag-o-sphere today. One hundred students line up to walk by one hundred closed lockers. The first student walks by opening every locker that is closed. The second student then walks by and opens every second locker that is closed and closes every second locker that &hellip; <a href=\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Opening Doors&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,6,12],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-math","tag-processing","tag-riddle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Opening Doors - Theory and Practice<\/title>\n<meta name=\"description\" content=\"Live-blogging the solution to a locker-door riddle.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Opening Doors - Theory and Practice\" \/>\n<meta property=\"og:description\" content=\"Live-blogging the solution to a locker-door riddle.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\" \/>\n<meta property=\"og:site_name\" content=\"Theory and Practice\" \/>\n<meta property=\"article:published_time\" content=\"2010-08-07T05:11:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T01:12:21+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\" \/>\n<meta name=\"author\" content=\"morgan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"morgan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\"},\"author\":{\"name\":\"morgan\",\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd\"},\"headline\":\"Opening Doors\",\"datePublished\":\"2010-08-07T05:11:58+00:00\",\"dateModified\":\"2022-11-21T01:12:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\"},\"wordCount\":631,\"publisher\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd\"},\"image\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\",\"keywords\":[\"math\",\"Processing\",\"riddle\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\",\"url\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\",\"name\":\"Opening Doors - Theory and Practice\",\"isPartOf\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\",\"datePublished\":\"2010-08-07T05:11:58+00:00\",\"dateModified\":\"2022-11-21T01:12:21+00:00\",\"description\":\"Live-blogging the solution to a locker-door riddle.\",\"breadcrumb\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage\",\"url\":\"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\",\"contentUrl\":\"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/morganredfield.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Opening Doors\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/morganredfield.com\/blog\/#website\",\"url\":\"https:\/\/morganredfield.com\/blog\/\",\"name\":\"Theory and Practice\",\"description\":\"Exploring life through science and art.\",\"publisher\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/morganredfield.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd\",\"name\":\"morgan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0da7fa0a0a07a8497d51de4300111d978b649e254fc1afa26dc67f3b83d24c38?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0da7fa0a0a07a8497d51de4300111d978b649e254fc1afa26dc67f3b83d24c38?s=96&d=mm&r=g\",\"caption\":\"morgan\"},\"logo\":{\"@id\":\"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/morganredfield.com\/blog\/author\/morgan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Opening Doors - Theory and Practice","description":"Live-blogging the solution to a locker-door riddle.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/","og_locale":"en_US","og_type":"article","og_title":"Opening Doors - Theory and Practice","og_description":"Live-blogging the solution to a locker-door riddle.","og_url":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/","og_site_name":"Theory and Practice","article_published_time":"2010-08-07T05:11:58+00:00","article_modified_time":"2022-11-21T01:12:21+00:00","og_image":[{"url":"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg","type":"","width":"","height":""}],"author":"morgan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"morgan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#article","isPartOf":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/"},"author":{"name":"morgan","@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd"},"headline":"Opening Doors","datePublished":"2010-08-07T05:11:58+00:00","dateModified":"2022-11-21T01:12:21+00:00","mainEntityOfPage":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/"},"wordCount":631,"publisher":{"@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd"},"image":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage"},"thumbnailUrl":"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg","keywords":["math","Processing","riddle"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/","url":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/","name":"Opening Doors - Theory and Practice","isPartOf":{"@id":"https:\/\/morganredfield.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage"},"image":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage"},"thumbnailUrl":"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg","datePublished":"2010-08-07T05:11:58+00:00","dateModified":"2022-11-21T01:12:21+00:00","description":"Live-blogging the solution to a locker-door riddle.","breadcrumb":{"@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#primaryimage","url":"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg","contentUrl":"http:\/\/morganredfield.com\/blog\/wp-content\/uploads\/2010\/08\/10lockers_timelapse.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/morganredfield.com\/blog\/2010\/08\/opening-doors\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/morganredfield.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Opening Doors"}]},{"@type":"WebSite","@id":"https:\/\/morganredfield.com\/blog\/#website","url":"https:\/\/morganredfield.com\/blog\/","name":"Theory and Practice","description":"Exploring life through science and art.","publisher":{"@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/morganredfield.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/15fce334735dd60ce7bb5712c44a62dd","name":"morgan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0da7fa0a0a07a8497d51de4300111d978b649e254fc1afa26dc67f3b83d24c38?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0da7fa0a0a07a8497d51de4300111d978b649e254fc1afa26dc67f3b83d24c38?s=96&d=mm&r=g","caption":"morgan"},"logo":{"@id":"https:\/\/morganredfield.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/morganredfield.com\/blog\/author\/morgan\/"}]}},"_links":{"self":[{"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":6,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/posts\/57\/revisions\/658"}],"wp:attachment":[{"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/morganredfield.com\/blog\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}