# Enigmatic Code

Programming Enigma Puzzles

## Puzzle 34: We compete. Who does what?

From New Scientist #1085, 12th January 1978 [link]

The jobs of my five employees, Alf, Bert, Charlie, Duggie and Ernie, have been changing rather frequently lately and I am afraid that I have got slightly out of touch. It was rather important for me, however, to find out who does what, as they had recently been having a test designed to find out more about their assorted capabilities and it was clearly important for the Managing Director to know just what had been happening in the past so that he could predict the future.

The information that I managed to get about their jobs and their places in the test (in which there were no ties) was as follows:

1. Bert was as many placed below the Worker as he was above the Door-Knob-Polisher.

2. The Door-Opener was three places above Charlie.

3. Alf’s place was even and the Door-Shutter’s place was odd.

4. The Bottle-Washer was two places above Ernie.

In what order did they come in the test, and what were their jobs?

[puzzle34]

### One response to “Puzzle 34: We compete. Who does what?”

1. Jim Randell 5 December 2018 at 7:38 am

I’ve only recently found out about the [[ enum ]] module in Python, which can be used for enumerated types, and appears to be available in most recent versions of Python that I have installed (2.7, 3.6, 3.7, but not PyPy 6.0).

The main advantage is that an element knows it’s own name, which makes it easier to do the output. The main disadvantage is the need to qualify the elements with type name.

Here I’ve used [[ IntEnum() ]] so I can use the values as indices into arrays.

This Python program runs in 89ms.

Run: [ @repl.it ]

```from enum import IntEnum
from itertools import permutations
from enigma import printf

# names of the employees
Name = IntEnum("Name", "Alf Bert Charlie Duggie Ernie", start=0)

# jobs
Job = IntEnum("Job", "Worker DoorKnobPolisher DoorOpener DoorShutter BottleWasher", start=0)

# map employees to positions (1 to 5)
# position: names -> (1 to 5)
for position in permutations((1, 2, 3, 4, 5)):

# 3. "Alf's place was even..."
if not(position[Name.Alf] % 2 == 0): continue

# map employees to jobs
# job: names -> jobs
for job in permutations(Job):

# 1. "Bert was placed as many places below the Worker as he was above the Door-Knob-Polisher"
if not(position[Name.Bert] - position[job.index(Job.Worker)] == position[job.index(Job.DoorKnobPolisher)] - position[Name.Bert] > 0): continue

# 2. "The Door-Opener was three places above Charlie"
if not(position[job.index(Job.DoorOpener)] + 3 == position[Name.Charlie]): continue

# 3. "... the Door-Shutters place was odd"
if not(position[job.index(Job.DoorShutter)] % 2 == 1): continue

# 4. "The Bottle-Washer was two places above Ernie"
if not(position[job.index(Job.BottleWasher)] + 2 == position[Name.Ernie]): continue

# output a solution
for (p, n, j) in sorted(zip(position, Name, job)):
printf("{p}: {n} ({j})", n=n.name, j=j.name)
printf()
```

Solution: 1st: Duggie (Door Opener); 2nd: Alf (Worker); 3rd: Bert (Bottle Washer); 4th: Charlie (Door Knob Polisher); 5th: Ernie (Door Shutter).

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