There once were four dwarfs who had been captured by orcs. The orcs, who liked playing games before eating, created the following set-up:
After digging some holes for the dwarfs, they pushed them inside in the order seen in the picture below. The dwarf to the left could only see the two middle dwarfs, while the right-most one was separated by a wall and thus couldn't see anybody else. The second dwarf from the left could only see the one immediately in front of him, who in turn couldn't see any other dwarf.
The orcs proceeded to put blue hats on two dwarfs and red hats on the other two, making sure none of them knew the color of their own hat but still letting them know the number of colored hats being used (two blue and two red). At this point the poor dwarfs were given five minutes for any of them to shout out the color of his own hat. The dwarfs knew the setup of this test and also that there were two red and two blue hats. In order to spice things up, the orcs then promised to free all the dwarfs if they solved their puzzle. If they failed, though, they'd be eaten. Which of the four dwarfs knew his own hat's color and saved the day?
[Answer]