**From New Scientist #2367, 2nd November 2002** [link]

There are four logicians, Anna, Barbara, Cara and Dora, who are in four rooms, P, Q, R and S, respectively. Each room is painted yellow or green. The distribution of paints is one of the following nine: YYGY (i.e. P is Y, Q is Y, R is G and S is Y), YYYG, YYYY, YYGG, YGGY, GYYY, GGYY, GGYG and GGGG. I give the list to the four logicians. Two of them, whenever they write anything down, always write the opposite of what they believe is true. Each logician has no outside knowledge of what is happening outside her room.

Anna gives me a piece of paper on which she has written, ‘the colour of room P is …’, with a colour in place of the three dots. I give the paper to Barbara who takes the information on it as being true. She deduces, from all the information she has, what she believes to be the colour of room S; she gives me a piece of paper on which she has written, ‘the colour of room S is …’.

I give the paper to Cara, who carries out a similar activity to Barbara, ending with Cara giving me a piece of paper with a statement that room P is a certain colour. I give the paper to Dora who carries out a similar activity to Barbara and Cara, ending with Dora giving me a piece of paper with a statement that room Q is a certain colour.

I give it to Anna who carries out a similar activity to Barbara, Cara and Dora, ending with Anna giving me a piece of paper with a statement that room R is a certain colour.

What are the colours of the four rooms?

[enigma1211]

### Like this:

Like Loading...

This Python program considers the possibilities and uses exceptions (actually assertions) to weed out cases where certain information cannot be deduced. It runs in 31ms.

Solution:The rooms are painted as follow’s: Anna’s room (P) is painted yellow; Barbara’s room (Q) is painted yellow; Cara’s room (R) is painted green; Dora’s room (S) is painted green.If A lies, B and C tell the truth, and D lies, we have the following sequence:

There is a second case where A lies, B tells the truth, C lies and D tells the truth. The sequence is the same up to C’s deduction: