From New Scientist #2591, 17th February 2007
The latest creation acquired by our local art gallery consists of six separate squares with labels such as “Doubt” and “Fury”, each of a different colour, including yellow and purple. The six squares have to be arranged at the gallery into a rectangle consisting of two rows with three squares in each row.
The curator remembered that “Charm” is above the red square (which is not “Angst”), that the blue square is between “Belief” and the orange square, and that the green square has no edge in common with “Envy”. He also remembered that the three labels in the top row are in alphabetical order, but in the bottom row neither the labels nor the colours are in alphabetical order.
So he arranged the squares satisfying all these conditions, but unfortunately he still got it wrong, thus infuriating the artist.
What (in alphabetical order of the labels) were the colours of the squares?
[enigma1430]
This Python program runs in 206ms. It’s a direct interpretation of the problem statement and checks the conditions over every possible permutation of the labels and colours, then looks for arrangements that have ambiguous orders.
Solution: The squares, in alphabetical order of the labels are: Green, Yellow, Blue, Orange, Purple and Red.
If you rearrange so the tests are in a different order to that stated in the puzzle text you can get the run time down to 77ms.
Here is a version adapted from my Python code for the classic Zebra/Water puzzle. http://arthurvause.blogspot.co.uk/2012/10/who-owns-zebra.html
The adaptation isn’t entirely satisfactory as there are several “reverse lookups” required.