# Enigmatic Code

Programming Enigma Puzzles

## Enigma 830: Post mix

In an inebriated state I tried to address two letters to each of five friends. I have listed my efforts below. Each envelope has four items:

– first name
– surname
– house name
– town

All the correct items occurred somewhere on the ten envelopes. But on each envelope the four items which I wrote all turned out to be from different people.

1: David Davis, Rose Cottage, Ely
2: Brian Clark, The Meadow, Carlisle
4: Alan Eyres, Waters’ Edge, Altrincham
5: Ed. Clark, Belle View, Carlisle
6: David Andrews, Waters’ Edge, Ely
7: Clive Brown, Belle View, Doncaster
8: Brian Eyres, Riverside, Doncaster
9: Clive Clark, Riverside, Ely
10: Ed. Davis, Rose Cottage, Carlisle.

What is Brian’s name and address?

[enigma830]

### One response to “Enigma 830: Post mix”

1. Jim Randell 27 March 2023 at 10:07 am

Fortunately each of the components of the 5 addresses are unique, so we can use them to stand for themselves.

This Python program runs in 63ms. (Internal runtime is 3.1ms).

Run: [ @replit ]

```from enigma import (cproduct, intersect, diff, unzip, uniq, printf)

# the 10 envelopes
envs = [
("David", "Davis", "Rose Cottage", "Ely"),
("Alan", "Eyres", "Waters' Edge", "Altrincham"),
("Ed.", "Clark", "Belle View", "Carlisle"),
("David", "Andrews", "Waters' Edge", "Ely"),
("Clive", "Brown", "Belle View", "Doncaster"),
("Brian", "Eyres", "Riverside", "Doncaster"),
("Clive", "Clark", "Riverside", "Ely"),
("Ed.", "Davis", "Rose Cottage", "Carlisle"),
]

# solve envs for the remaining groups gs
def solve(envs, gs, ss=[]):
# are we done?
if not gs[0]:
yield ss
else:
# find the first component
n = gs[0][0]
# choose the remaining components
for rs in cproduct(gs[1:]):
cs = (n,) + rs
# check each envelope contains at most one of these components
if all(len(intersect([cs, xs])) < 2 for xs in envs):
# solve for the remaining components
yield from solve(envs, list(diff(xs, {x}) for (xs, x) in zip(gs, cs)), ss + [cs])

# group the components together
gs = list(list(uniq(xs)) for xs in unzip(envs))

# find solutions
for ss in solve(envs, gs):
for (i, (f, s, h, t)) in enumerate(ss, start=1):
printf("{i}: {f} {s}, {h}, {t}")
printf()
```

Solution: Brian Andrews, Belle View, Altrincham.