# Enigmatic Code

Programming Enigma Puzzles

## Enigma 441: The coloured painting

From New Scientist #1591, 17th December 1987 [link]

I looked down at the body slumped over my desk. One hand held my card “Newton Harlowe — Private detective”, and the other a painting. All I knew about painting came from watching my secretary Velda doing her nails. However, I could see in the dim light that is was a 6 × 6 array of small squares, each coloured red or blue or green. As the neon lights on the nightclubs opposite my office window flashed on and off and the light reflected from the wet sidewalks, I was able to make out the vertical columns of the painting. I saw:

though that was not necessarily the order they occurred in the painting. Suddenly the door opened and a raincoated figure with an automatic entered. There was a loud bang and everything went black.

I came round to find myself lying next to the body of a blonde on the floor of a living room. From the sound of the surf outside I could tell it was a beach-house. There on the wall was the painting. The moonlight shone onto it through the shutters. As they moved in the breeze I was able to make out the horizontal rows of the painting. I saw:

though again not necessarily in the right order. Just then a police siren sounded outside. I was going to have to do some explaining, and that painting was the key.

Reproduce the painting.

[enigma441]

### One response to “Enigma 441: The coloured painting”

1. Jim Randell 23 March 2018 at 6:27 am

It’s easy enough to consider the all the permutations of the rows, and see if the collection of columns produced matches those given. (Or we could permute the columns and see if the collection of rows produced matches the rows we are given).

This Python program runs in 107ms.

Run: [ @repl.it ]

```from itertools import permutations
from collections import Counter
from enigma import join, printf

# the columns (in some order)
cols = ("RBGGBR", "BBGRRG", "GGRBRB", "RGBRBG", "GRRBGB", "BRBGGR")

# the rows (in some order)
rows = ("BGBRGR", "RBBGRG", "GGRBRB", "RRGBGB", "GBRRBG", "BRGGBR")

# turn the columns into a multiset
cols = Counter(cols)

# consider the possible orderings for the rows
for rs in permutations(rows):
# the corresponding columns
cs = Counter(join(x) for x in zip(*rs))
# check they match the given columns
if cs == cols:
# output a solution
for r in rs:
printf("{r}")
printf()
```

Solution: The painting is reproduced below:

This site uses Akismet to reduce spam. Learn how your comment data is processed.