Skip to content

Instantly share code, notes, and snippets.

@schleary
Last active August 29, 2015 14:02
Show Gist options
  • Save schleary/1221d6c80dfaa62268f5 to your computer and use it in GitHub Desktop.
Save schleary/1221d6c80dfaa62268f5 to your computer and use it in GitHub Desktop.
Markdown Explanation of a Solution to a Logic Problem Involving Painted Gnomes

###G N O M E   C A V E   L O G I C   A S S E S S M E N T === ###1). How did they do this? *** * The first gnome to leave the cave had little to do but stand out front and wait for the others.
  • The second gnome came out and simply stood next to the first. Regardless of whether they were painted the same color or not, they were instantly sorted; they were either grouped together as the same color, or sorted with one color on each side.

  • Then the third gnome came out, and did one of two things: if the first two gnomes were differently colored, then the third gnome simply stood between them, to be automatically absorbed by the correct side. If, however, the first two gnomes were painted the same color, this third gnome self-sorted by standing at either end of the first two. In this way, gnome #3 was sorted, regardless of color.

  • The fourth gnome came out, and seeing the first three gnomes sorted, followed the same decision-making process as the previous gnome, either insinuating itself directly between the reds and blues, or, if they were all the same color up to this point, then standing off to one side to potentially (though not necessarily) form a new color group.

  • In this fashion, the rest of the gnomes continued to self-sort until all were sorted in a single line, with red foreheads on one side, and blue foreheads on the other.



###2). How did you arrive at that answer? Show your process.


First, I looked for potential tricks and loopholes:

Could they all go outside and try to find a lake or body of water so they could peer into their reflections? Could they simply scratch the paint off with their fingernails and determine their fates that way? Remembering that I was dealing with a logic problem and not a riddle, I realized I had to approach the problem more systematically.

Second, I tried to see if I could figure out some algorithm:

It occurred to me that the gnomes might be able to sort themselves before leaving the cave. I knew that this would be difficult or impossible, given that the gnomes wouldn't have a single piece of information to start from, but I had a vague memory that as a child, I used to be able to solve a rubik's cube without looking, and I also knew that each gnome was either one color or the other, which I felt might limit the necessity for having a given starting-point.

I spent some time with pennies and nickles, splitting random quanties of each into two equally-sized groups and experimenting with moving them into different sorting patterns. I thought that maybe if I zippered them together and then split the zipper in half a certain number of times, it might order them. I knew it was unlikely, but the rubik's cube was echoing in my memory. After several different attempts at patterned permutations, I looked up rubik's cube videos online to see if people could actualy solve them blindfolded. It turns out they can, but only if they look at the cube first. A little more research confirmed that it is impossible to blindly sort in the way I had imagined.

Third, I tried to think about it more experientially:

How would I try to do this if I were in this situation myself? I thought about the gnomes forming two cues outside the cave, one for blue and one for red. Perhaps it could be discussed ahead of time - red on the right, blue on the left. The first gnome, clueless, could stand to the right, while the subsequent gnome would come out and stand where the previous gnome should be, which would cause the previous gnome to move or stay. And in this fashion, each gnome would come out and show the previous gnome where to be, until the last. For the last gnome, the two groups of gnomes, having by now identified themselves, would each walk toward or away from the gnome, ensuring that the correct group would absorb this final gnome.

However, while discussing this solution with a friend, I realized that my approach relied quite heavily on non-verbal communication, so I had to scrap the idea.

Finally, I realized that "sort" doesn't necessarily mean "separate." I could sort the gnomes within a single line:

When this occurred to me, it became instantly clear. Up until this point, I had been stuck on assuming that "sorted" meant to group separately. In actuality, two gnomes standing side-by-side are instantly sorted. Any number of gnomes are sorted within a line, so long as the reds are on one side, and the blues are on another. And since each gnome leaving the cave can see how those outside are sorted, the newest gnome, though ambiguous to itself, needs only to be spliced within the boundary between two groups (or, if the gnomes are all the same color, then potentially start a new group at the end), and be absorbed into the correct side automatically (which will be evident to the next gnome who leaves the cave).


###3). What other possible answers are there?


Short of scratching the paint off their foreheads, using some form of non-verbal communication outside the cave, or some other form of cheating, I don't see any other way to solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment