{"id":1909,"date":"2018-06-15T11:20:55","date_gmt":"2018-06-15T01:20:55","guid":{"rendered":"http:\/\/www.somethinkodd.com\/oddthinking\/?p=1909"},"modified":"2018-06-15T11:21:41","modified_gmt":"2018-06-15T01:21:41","slug":"the-snail-puzzle","status":"publish","type":"post","link":"https:\/\/www.somethinkodd.com\/oddthinking\/2018\/06\/15\/the-snail-puzzle\/","title":{"rendered":"The Snail Puzzle"},"content":{"rendered":"<p>[*FX*: Sound of man blowing dust off and old engine, opening the fuel valve, adjusting the throttle and then yanking the pull cord a couple of times until the motor starts up.]<\/p>\n<p>Would you look at that? The blog still works.<\/p>\n<p>I&#8217;ve come back for a couple of quick posts. I used to document all my attempts at using a <a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/2014\/07\/29\/light-up-puzzle\/\">Puzzle Solving Framework<\/a>. I may as well keep it up-to-date with developments.<\/p>\n<h3>Introducing the Snail puzzle<\/h3>\n<p>Two months ago, I decided I wanted to tackle the Snail puzzle (which I found in <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.andreasabbatini.logicgamestk\">100 Logic Games<\/a>).<\/p>\n<p>The gameboard is a grid of squares, which are marked out as a spiral. Each cell can marked as &#8220;empty&#8221; with a dot, or marked as having a 1, 2, or 3 in it. Some are filled in as initial clues.<\/p>\n<p><a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_unsolved.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_unsolved-279x300.png\" alt=\"A picture of an unsolved Snail game\" width=\"279\" height=\"300\" class=\"alignleft size-medium wp-image-1912\" srcset=\"https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_unsolved-279x300.png 279w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_unsolved-140x150.png 140w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_unsolved.png 402w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/a><\/p>\n<p>The rules are are: <\/p>\n<ul>\n<li>Each number must appear exactly once in each row and column.<\/li>\n<li>As you follow the spiralling path from the outside to the centre, the numbers must repeat the sequence 1-2-3, starting with a 1 and finishing with a 3.<\/li>\n<\/ul>\n<h3>Solving the Snail<\/h3>\n<p>I implemented this a few months ago, so I am a little vague about my motivations.<\/p>\n<p>I recall I had some ideas about adopting a different approach than normal. I was considering trying a more brute-force method, because I thought I could model the problem in a way that the number of combinations to try was very small (i.e. in the millions).<\/p>\n<p>When I did the maths, it didn&#8217;t scale well. The 5&#215;5 puzzle above could be solved quickly, but an 11&#215;11 was infeasible.<\/p>\n<p>So, I used my tried-and-true technique of the framework I wrote all those years ago.<\/p>\n<p>I had another hypothesis that a couple of simple logical inference rules might be sufficient to solve the puzzles, if I modelled it right.<\/p>\n<p>In particular, I didn&#8217;t model each cell as having one of four values, but as having one of six values: 1, 2, 3, \u00e2\u2014\u008f1, \u00e2\u2014\u008f2, \u00e2\u2014\u008f3.<\/p>\n<p>The three dotted values were displayed as a single dot (i.e. an empty cell), but behind the scenes the rules were more complex. A \u00e2\u2014\u008f1 cell could only be followed by a 1 cell or another \u00e2\u2014\u008f1 cell. A 1 cell could only be followed by a 2 cell, or a \u00e2\u2014\u008f2 cell. This allowed information about what the last cell was to be carried around the corners.<\/p>\n<p>It seemed to work. A implemented those constraints, plus the typical exactly-one-number-per-row exclusion rules &#8211; i.e. if there is a 3 in this row, no other cell in this row can be a 3. If no other cell *might* be a 3 in this row, this cell must be a three.<\/p>\n<p>Those rules were sufficient to solve most of the puzzles I sampled.<\/p>\n<p><a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_solved.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_solved-279x300.png\" alt=\"\" width=\"279\" height=\"300\" class=\"alignleft size-medium wp-image-1911\" srcset=\"https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_solved-279x300.png 279w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_solved-140x150.png 140w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game1_solved.png 402w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved.png\"> <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved-290x300.png\" alt=\"\" width=\"290\" height=\"300\" class=\"alignright size-medium wp-image-1910\" srcset=\"https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved-290x300.png 290w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved-145x150.png 145w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved.png 738w\" sizes=\"auto, (max-width: 290px) 100vw, 290px\" \/><\/a><\/p>\n<p>However, some puzzles didn&#8217;t succumb to these rules. Here is a game that the software got stuck on:<\/p>\n<p><a href=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved.png\" alt=\"\" width=\"738\" height=\"763\" class=\"alignleft size-full wp-image-1910\" srcset=\"https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved.png 738w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved-145x150.png 145w, https:\/\/www.somethinkodd.com\/oddthinking\/wp-content\/uploads\/2018\/06\/Game3_partiallysolved-290x300.png 290w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/a><\/p>\n<p>The small grey numbers describe the cell&#8217;s address (position in the spiral and grid co-ordinates) The small colourful numbers and dots represent the internal state of the cells &#8211; legal options that the software han&#8217;t been able to eliminate.<\/p>\n<p>Look at cells 24 and 25. One of those must be a 1, so until a 2 is encountered, there can be no 3. So, we can eliminate the 3 option from calls 25, 26, 27 and 28. If you do so, the solver can take over from there and complete the puzzle.<\/p>\n<p>The complexity of the next level of logic to detect situations like this made it seem too brute-force for me to consider implementing it.<\/p>\n<p>I left it there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[*FX*: Sound of man blowing dust off and old engine, opening the fuel valve, adjusting the throttle and then yanking the pull cord a couple of times until the motor starts up.] Would you look at that? The blog still works. I&#8217;ve come back for a couple of quick posts. I used to document all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"yes","footnotes":""},"categories":[33,34],"tags":[91],"class_list":["post-1909","post","type-post","status-publish","format-standard","hentry","category-puzzle-solving","category-software-development","tag-puzzles"],"_links":{"self":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/comments?post=1909"}],"version-history":[{"count":12,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1909\/revisions"}],"predecessor-version":[{"id":1925,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/1909\/revisions\/1925"}],"wp:attachment":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/media?parent=1909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/categories?post=1909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/tags?post=1909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}