Enigmatic Code

Programming Enigma Puzzles

Enigma 830: Post mix

From New Scientist #1985, 8th July 1995 [link] [link]

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
3: Ed. Andrews, Riverside, Bradford
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?



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"),
      ("Brian", "Clark", "The Meadow", "Carlisle"),
      ("Ed.", "Andrews", "Riverside", "Bradford"),
      ("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
        # 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}")

    Solution: Brian Andrews, Belle View, Altrincham.

    The correct addresses are:

    Brian Andrews, Belle View, Altrincham
    David Brown, Riverside, Carlisle
    Alan Clark, Rose Cottage, Doncaster
    Clive Davis, Waters’ Edge, Bradford
    Ed. Eyres, The Meadow, Ely

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: