{"id":347,"date":"2014-11-09T21:00:44","date_gmt":"2014-11-10T05:00:44","guid":{"rendered":"http:\/\/mostlymental.com\/?p=347"},"modified":"2014-11-24T19:36:16","modified_gmt":"2014-11-25T03:36:16","slug":"towers-of-hanoi","status":"publish","type":"post","link":"http:\/\/mostlymental.com\/?p=347","title":{"rendered":"Towers of Hanoi"},"content":{"rendered":"<p>Hello everyone!<\/p>\n<p>I'm back, and I've got lots of exciting math to share, so let's get to it!\u00a0 This week, I'd like to talk about a classic puzzle called the Towers of Hanoi.\u00a0 To start, we have a board with three pegs, as shown below, one of which has a stack of disks on it.\u00a0 We want to move all the disks from the starting peg to either of the other pegs.<a href=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_basic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-360 aligncenter\" src=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_basic-300x118.png\" alt=\"hanoi_basic\" width=\"300\" height=\"118\" srcset=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_basic-300x118.png 300w, http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_basic.png 468w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>However, we have two constraints: we can only move one disk at a time, from one peg to another, and we can never place a disk on top of a smaller disk.\u00a0 So in the example below, we can move the middle disk onto the larger disk on the left, but not the smaller disk on the right.<a href=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_move.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-361 aligncenter\" src=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_move.png\" alt=\"hanoi_move\" width=\"220\" height=\"185\" \/><\/a><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p>So how do we solve it?\u00a0 The key insight here is that a disk can only move when all the smaller disks are stacked on another peg.\u00a0 So in the example below, we can only move the red disk to the third peg once we've moved the yellow, green, and blue disks to the second.\u00a0 So the problem of moving all four disks can be broken down into moving the top three to another peg, moving the largest disk, then moving the top three back on top of the largest. <a href=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_recurse1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-368 aligncenter\" src=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_recurse1-300x255.png\" alt=\"hanoi_recurse\" width=\"300\" height=\"255\" srcset=\"http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_recurse1-300x255.png 300w, http:\/\/mostlymental.com\/wp-content\/uploads\/2014\/11\/hanoi_recurse1.png 467w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>This brings up an important concept.\u00a0 We've taken the problem with <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_a87ff679a2f3e71d9181a67b7542122c.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks and reduced it to the problem with <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_eccbc87e4b5ce2fe28308fd9f2a7baf3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>.\u00a0 Or, more generally, we've reduced the problem with <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_488968c8363007fe20e033f70ad0b931.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks to the problem with <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>.\u00a0 We've found a procedure for solving the problem given a procedure for solving the same problem in a smaller case.\u00a0 We call such a procedure a recursive algorithm.\u00a0 (If this reminds you of <a href=\"http:\/\/mostlymental.com\/?p=103\">induction<\/a>, you're absolutely on the right track.)<\/p>\n<p>&nbsp;<\/p>\n<p>Next, we might wonder how many steps it takes to solve the Towers of Hanoi.\u00a0 With <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c4ca4238a0b923820dcc509a6f75849b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disk, we only need <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c4ca4238a0b923820dcc509a6f75849b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> step: just move the disk to another peg.\u00a0 With <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c81e728d9d4c2f636f067f89cc14862c.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks, we need to move disk <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c4ca4238a0b923820dcc509a6f75849b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> to one peg, disk <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c81e728d9d4c2f636f067f89cc14862c.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> to another, then disk <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c4ca4238a0b923820dcc509a6f75849b.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> back onto disk <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_c81e728d9d4c2f636f067f89cc14862c.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>, for a total of <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_eccbc87e4b5ce2fe28308fd9f2a7baf3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> moves.\u00a0 With <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_eccbc87e4b5ce2fe28308fd9f2a7baf3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks, we need <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_8f14e45fceea167a5a36dedd4bea2543.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> moves, and with <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_a87ff679a2f3e71d9181a67b7542122c.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks, we need <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_9bf31c7ff062936a96d3c8bd1f8f2ff3.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>.\u00a0 What's the pattern here?<\/p>\n<p>Let's call <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_514884be093e9ab7909b0d394e7b74d2.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> the number of steps it takes to move <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks to another peg.\u00a0 Then <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_bdcf15eae607e221bf73ec68eceaa3b7.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>, <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_52f15a8073ec54f2bfaa56065acfc8d8.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>, and so on.\u00a0 As we saw above, we can move <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> disks by moving <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_f69fdffb82267fca1be8c6913635b318.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script> twice, with an extra move in the middle.\u00a0 Thus, <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_746a1c56d3c77f81697b08ae938b0417.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>.\u00a0 This relationship lets us solve to get <span class='MathJax_Preview'><img src='http:\/\/mostlymental.com\/wp-content\/plugins\/latex\/cache\/tex_623fc05c5d89316bb2ca898518806b0c.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>.<\/p>\n<p>&nbsp;<\/p>\n<p>There are a lot of ways we might extend the Towers of Hanoi.\u00a0 The simplest way is to add a fourth peg.\u00a0 It turns out this makes the problem of finding the shortest sequence of moves hard.\u00a0 In fact, no one has solved it yet; it remains an open problem.\u00a0 If you're curious, I'd love to discuss it further in the comments.<\/p>\n<p>There's much more that can be said about the Towers of Hanoi, so I've devoted next week's post to one feature that I find particularly cool.\u00a0 I hope you'll join me then.<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=http%3A%2F%2Fmostlymental.com&amp;t=Towers%20of%20Hanoi&amp;s=100&amp;p[url]=http%3A%2F%2Fmostlymental.com&amp;p[images][0]=http%3A%2F%2Fmostlymental.com%2Fwp-content%2Fuploads%2F2014%2F11%2Fhanoi_move.png&amp;p[title]=Towers%20of%20Hanoi\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=http%3A%2F%2Fmostlymental.com&amp;text=Hey%20check%20this%20out\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=http%3A%2F%2Fmostlymental.com&amp;title=Towers%20of%20Hanoi\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-pinterest nolightbox\" data-provider=\"pinterest\" target=\"_blank\" rel=\"nofollow\" title=\"Pin it with Pinterest\" href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=http%3A%2F%2Fmostlymental.com&amp;media=http%3A%2F%2Fmostlymental.com%2Fwp-content%2Fuploads%2F2014%2F11%2Fhanoi_move.png&amp;description=Towers%20of%20Hanoi\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"pinterest\" title=\"Pin it with Pinterest\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/pinterest.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&amp;url=http%3A%2F%2Fmostlymental.com&amp;title=Towers%20of%20Hanoi\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Towers%20of%20Hanoi&amp;body=Hey%20check%20this%20out:%20http%3A%2F%2Fmostlymental.com\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png\" \/><\/a><a class=\"synved-social-credit\" target=\"_blank\" rel=\"nofollow\" title=\"WordPress Social Media Feather\" href=\"http:\/\/synved.com\/wordpress-social-media-feather\/\" style=\"color:#444;text-decoration:none;font-size:8px;margin-left:5px;vertical-align:10px;white-space:nowrap\"><span>by <\/span><img loading=\"lazy\" decoding=\"async\" style=\"display: inline;margin:0;padding:0;width:16px;height:16px\" width=\"16\" height=\"16\" alt=\"feather\" src=\"http:\/\/mostlymental.com\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/icon.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>Hello everyone! I'm back, and I've got lots of exciting math to share, so let's get to it!\u00a0 This week, I'd like to talk about a classic puzzle called the Towers of Hanoi.\u00a0 To start, we have a board with three pegs, as shown below, one of which has a stack of disks on it.\u00a0 &hellip; <a href=\"http:\/\/mostlymental.com\/?p=347\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Towers of Hanoi<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-347","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/posts\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mostlymental.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347"}],"version-history":[{"count":10,"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/posts\/347\/revisions"}],"predecessor-version":[{"id":369,"href":"http:\/\/mostlymental.com\/index.php?rest_route=\/wp\/v2\/posts\/347\/revisions\/369"}],"wp:attachment":[{"href":"http:\/\/mostlymental.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mostlymental.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mostlymental.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}