Sorting the Hats

No, this isn't about the Sorting Hat that wanted to put Harry Potter in the wrong house of Hogwarts, it's a puzzle.

Imagine that there are 60 dwarves that live in a cave. All dwarves wear hats. Some dwarves wear red hats, others wear blue hats. For some reason, no dwarf knows the color of his own hat, and in the cave, it's also too dark to see any other dwarf's hat color.
The dwarves now want to stand in a line outside their cave, so that the line consists of all the red-hatted dwarves first, and then all the blue-hatted ones. Or the other way round, that's irrelevant. The only important thing is that all the blue guys stand next to each other, and so do all the reds.
These dwarves must exit the cave one by one and immediately take their place in the line (the first dwarf can stands wherever he likes). They can't talk among each other, and they can't change their position once they've picked one.
How do the dwarves manage to line up in two groups, one red, one blue?

Here's the solution. I've rot13'd it, go to the rot13 site to decode.

Qjnes ahzore 1 whfg fgnaqf naljurer.
Qjnes ahzore 2 fgnaqf gb gur yrsg be evtug bs qjnes 1.
Nal sbyybjvat qjnes qbrf gur sbyybjvat:
-Vs nyy gur qjneirf' ungf ner gur fnzr pbybe, ur fgnaqf ba rvgure fvqr.
-Vs gurer ner gjb pbybef va gur yvar, gur qjnes fdhrrmrf va gur cbfvgvba jurer bar pbybe raqf naq gur arkg bar ortvaf.
Guvf jnl, gur qjnesf ner nyjnlf yvarq hc nf oyhr svefg, erq arkg, be ivpr irefn.

Posted by cronopio at 02:35 PM, December 28, 2005