Problem of the Day
A new programming or logic puzzle every Mon-Fri

Hat Escape

Three prisoners of reasonable intelligence are brought in to an arena and are told they will be allowed to walk away free if they can solve the game master's puzzle.

The captives are lined up in order of height, and are tied to stakes. The man in the rear can see the backs of his two friends, the man in the middle can see the back of the man in front, and the man in front cannot see anyone. The prisoners are then shown five hats. Three of the hats are black and two of the hats are white.

Blindfolds are then placed over each man's eyes and a hat is placed on each man's head. The two left over hats are hidden. The blindfolds are then removed and the game master makes an announcement. If any one of the prisoners can guess what color hat he is wearing they can all leave unharmed.

The man in the rear who can see both of his friends' hats but not his own says, "I don't know". The middle man who can see the hat of the man in front, but not his own says, "I don't know". The front man who cannot see anyone's hat says "I know!"

How did he know the color of his hat and what color was it?

Enjoy your weekend!

Permalink: http://problemotd.com/problem/hat-escape/

Comments:

  • Anonymous - 10 years, 8 months ago

    The man in the rear said "I don't know", so there are only 2 possibles for the hat in font of him: [black, black] or [black, white]. Because if the 2 hat in font of him is [white,white], then it's absolutely that his hat is black(only 2 white hat).

    So the man in the middle now know that the 2 possibles:[black,black] or [black, white]. But he also said "I don't know", because he know the first one's hat is black. So he cannot judge the hat on his head is black or white.

    And at last, the front man who cannot see anyone's hat now know, the hat on his head is black.

    reply permalink

  • Max Burstein - 10 years, 8 months ago

    Indeed you are correct. Nicely done.

    reply permalink

  • Anonymous - 10 years, 8 months ago

    Guy Three does not know because the permutation in front of him are either. [B,B] [W,B]

    Guy Two would of been able to work it out if Guy one was wearing a W hat, but he's not so he does not know.

    So Guy one knows he must be wearing a black hat if Guy Two did not know that he was wearing a W hat.

    reply permalink

  • Anonymous - 10 years, 8 months ago

    The first guy would say I know only if the other guys where wearing [W,W].

    Since he didn't the possibilities are now: [W,B], [B,W], or [B,B].

    If the second guy was seeing a White hat in front of him, and the first guy said "I don't know", then he must be wearing a Black hat, so he would say "I know". He didn't so the third guy is wearing a Black one.

    reply permalink

  • Kocsen - 10 years, 8 months ago

    Python solution. I essentially split lyrics by groupings (blank line) and keep track of their count in a dictionary. The highest count is the chorus!

    Worked with Happy by Williams, and a couple Bruno Mars Songs.

    def find_chorus(filename):
        # Dictionary that keeps track of repeated lines
        group = {}
        largest = 0            # Counter for group repetitions
        potential_chorus = ''  # Temp variable represents different sections
        chorus = ''            # Variable set when chorus is found
        with open(filename,'r') as song:
            for line in song.readlines():
                if line == '' or line == '\n':
                    # We now have a section. Lets check if its in our group of sections
                    if potential_chorus in group:
                        # It is! Let's ++ its count and check if its repeated the most
                        group[potential_chorus] += 1
                        if group[potential_chorus] > largest:
                            largest = group[potential_chorus]
                            chorus = potential_chorus
                    else:
                        # The section is new, let's add it
                        group[potential_chorus] = 1
    
                    # Clear group
                    potential_chorus = ''
                else:
                    potential_chorus += line
    
    
        print("I think the potential chorus is:\n" + chorus)
        print("With a count of %d", largest)
    
    if __name__ == "__main__":
        find_chorus("song.txt")
    

    reply permalink

  • Kocsen - 10 years, 8 months ago

    Wow totally wrong problem of the day. Disregard

    reply permalink

  • Pearce Keesling - 10 years, 8 months ago

    If the man in the rear doesn't know his color it means that the two in front are not BOTH wearing white (if they were he would have to have black).

    If the middle man knows this and still doesn't know his own color that means that the man in front has a black hat (both of them could potentially have black). If the front man had had a white hat he would know that he had a black hat.

    The man in front knows these facts and so he knows he is wearing a black hat.

    This is the first logic puzzle I've actually been able to solve, usually I just do the programming problems.

    reply permalink

  • Pearce Keesling - 10 years, 8 months ago

    If the man in the rear doesn't know his color it means that the two in front are not BOTH wearing white (if they were he would have to have black).

    If the middle man knows this and still doesn't know his own color that means that the man in front has a black hat (both of them could potentially have black). If the front man had had a white hat he would know that he had a black hat.

    The man in front knows these facts and so he knows he is wearing a black hat.

    This is the first logic puzzle I've actually been able to solve, usually I just do the programming problems.

    reply permalink

Content curated by @MaxBurstein