A logician invites 6 of his logician friends to help him celebrate his birthday. Each of the 6 guests is wearing a hat which is either red, yellow, or blue, and the logician host informs them all that there is at least 1 of each color. After they eat the cake, the host stands up and exclaims there is a special party prize for the first person who can deduce what color hat is on their head. The party guests all looked around the room at each other but no one claimed the prize immediately. Suddenly all 6 guests stood up and correctly identify what color hat was on their head.

What were the colors of their hats and how did they know?