The poor gingerbread men want to survive to Xmas (they don't mind being eaten afterwards). If at least one of them doesn't guess his hat correctly, they will all be cruelly eaten before Xmas. This is a modified version of some puzzles I found out there...

Will you save them?

They can guarantee at least two of them guess correctly with the following strategy

Assign two of them to guess that there will be an odd number of black hats in total and make the guess for their own hat based on that outcome.
Assign the other three to guess that there will be an even number of black hats in total and make the guess for their own hat based on that.
One of these groups is guaranteed to be right.

• Maybe rephrase the last sentence to "At least one person in ..." Commented Nov 6, 2020 at 19:54
• Incredible answer, so fast too! How did you do it so quickly?
– PDT
Commented Nov 7, 2020 at 5:13

Pair them up. In each pair (X,Y), X guesses the colour of Y's hat, and Y guesses the opposite colour of X's hat, so clearly exactly one of them gets the right colour. This already ensures at least 2 guess the right colour. The odd one out (that is not in a pair) can guess randomly, which would ensure that the average number of correct guesses is exactly half of the total number of friends.

(By the way, I think that half is in fact optimal but don't see an obvious easy proof.)