Enigmatic Code

Programming Enigma Puzzles

Enigma 187: Supergrasses

From New Scientist #1332, 18th November 1982 [link]

Who masterminded the Pizza Snatch, the Rectory Job, the Museum Swindle, the Gas Fire and the Guano Heist? The supergrasses have been singing like birds. Alas, they do not all sing the same tune. But it is no less embarrassing for that, as they all name the same three pillars of our gallant constabulary, P. C. Plant, Inspector Hound and Commissioner Cod.

Here, in tabular form, is the word according to Fingers Flanagan, Harry the Horse, Sam Snout, Tell-tale Ted and Willie Whisper. Please take it that each is right in exactly two of his allegations and work out the villain of each case.

[enigma187]

One response to “Enigma 187: Supergrasses”

1. Jim Randell 28 April 2014 at 9:00 am

It’s easy enough to examine all the possibilities. This Python program runs in 41ms.

```from itertools import product
from enigma import printf

# grasses information
grass = ('PCPHC', 'PCHCH', 'CHCPH', 'HHPCC', 'PPCPC')

# assign a culprit to each job
for jobs in product('PHC', repeat=5):
# and check each grass has exactly two hits
if all(tuple(a == b for (a, b) in zip(jobs, g)).count(True) == 2 for g in grass):
(PS, RJ, MS, GF, GH) = jobs
printf("PS={PS} RJ={RJ} MS={MS} GF={GF} GH={GH}")
```

Solution: Commissioner Cod was the villain in all the cases.