# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1392: 512 paintings

From New Scientist #2552, 20th May 2006

That great artist Pussicato has just held an exhibition of 512 different paintings. Each painting consists of a three-by-three array of small squares and each square is coloured red or green. Pussicato gives each painting a value which he calculates as follows. He writes down the three horizontal rows, reading each from left to right, and the three vertical rows, reading each from top to bottom. This gives him six 3-sequences. He counts how many of the six are different and that is the value of the painting. For example, the diagramÂ has 3-sequences RRG, GRG, GGG, RGG, RRG, GGG and value 4.

How many paintings in the exhibition had (a) value 1, (b) value 2, (c) value 6?

[enigma1392]

### One response to “Enigma 1392: 512 paintings”

1. Jim Randell 15 September 2013 at 8:26 am

It’s straightforward to generate all the paintings and record the value for each one. This Python program runs in 35ms.

```# a b c
# d e f
# g h i

from collections import Counter
from itertools import product
from enigma import printf

r = Counter()
# generate all sequences
for (a, b, c, d, e, f, g, h, i) in product('RG', repeat=9):
# count the different sequences
ss = set((
a + b + c, d + e + f, g + h + i,
a + d + g, b + e + h, c + f + i,
))
r[len(ss)] += 1

for k in sorted(r.keys()):
printf("{k}: {v}", v=r[k])
```

Solution: (a) 2 paintings have value 1; (b) 18 paintings have value 2; (c) 24 paintings have value 6.

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