# Enigmatic Code

Programming Enigma Puzzles

## Enigma 504: Hooray for Hollywood

From New Scientist #1656, 18th March 1989 [link]

Twentieth Century Lion Studios has just held a week-long film festival celebrating 60 years of talking pictures. It first selected seven of the studio’s legendary stars. It then chose seven of the studio’s classic films so that each of the 21 possible pairs of stars appeared together in one of the films.

The stars were selected from Fred Astride, Humphrey Bigheart, Joan Crowbar, Bette Daybreak, Judy Garage, Clark Gatepost, Katherine Hipbone, Barbara Standup, James Student, Spencer Treacle, John Weighing. The films were chosen from the following list in which each film is given with its stars:

Cosiblanket, JC, JG, BS
Top Hit, BD, JG, KH
Stagecrouch, HB, CG, KH
A Star is Bone, HB, JC, JS
Mildred Purse, CG, ST, JW
High None, HB, JG, ST
King Koala, FA, JG, CG
Random Harpist, BD, KH, JS
Now Forager, JC, BD, CG
Mrs Minimum, CG, JS, JW
The Adventures of Robin Hoop, KH, BS, JW
The Maltese Foghorn, FA, JC, ST
Mr Deeds goes to Tune, BS, JS, ST
Meet me in St Lucy, BD, CG, BS
Gone with the Wine, FA, HB, BD
Singing in the Rind, FA, JC, KH
Mutiny on the Bunting, BD, ST, JW
The Best Years of our Lifts, FA, HB, BS
Double Identity, FA, JG, JS

Which seven films were selected?

[enigma504]

### One response to “Enigma 504: Hooray for Hollywood”

1. Jim Randell 17 June 2019 at 8:35 am

With 7 stars there are C(7, 2) = 21 possible pairings. And each film has 3 stars, so provides C(3, 2) = 3 pairings. So a choice of 7 films that provides all possible pairings of the chosen 7 stars means that no pairings can be superfluous or duplicated.

This Python program runs in 270ms.

Run: [ @repl.it ]

```from enigma import subsets, union, join, printf

films = {
'Cosiblanket': 'JC, JG, BS',
'Top Hit': 'BD, JG, KH',
'Stagecrouch': 'HB, CG, KH',
'A Star is Bone': 'HB, JC, JS',
'Mildred Purse': 'CG, ST, JW',
'High None': 'HB, JG, ST',
'King Koala': 'FA, JG, CG',
'Random Harpist': 'BD, KH, JS',
'Now Forager': 'JC, BD, CG',
'Mrs Minimum': 'CG, JS, JW',
'The Adventures of Robin Hoop': 'KH, BS, JW',
'The Maltese Foghorn': 'FA, JC, ST',
'Mr Deeds goes to Tune': 'BS, JS, ST',
'Meet me in St Lucy': 'BD, CG, BS',
'Gone with the Wine': 'FA, HB, BD',
'Singing in the Rind': 'FA, JC, KH',
'Mutiny on the Bunting': 'BD, ST, JW',
'The Best Years of our Lifts': 'FA, HB, BS',
'Double Identity': 'FA, JG, JS',
}

# map the films to stars and pairs of stars
stars = dict()
pairs = dict()
for (k, v) in films.items():
ss = sorted(v.split(", "))
stars[k] = set(ss)
pairs[k] = set(subsets(ss, size=2))

# choose 7 films
for fs in subsets(films.keys(), size=7):
# count the total number of stars in all the films:
ss = union(stars[f] for f in fs)
# there should be 7
if len(ss) != 7: continue

# count the total number of pairs in all the films:
ps = union(pairs[f] for f in fs)
# there should be 21
if len(ps) != 21: continue

# output the solution
fmt = lambda ss: join(ss, sep="; ")
printf("{fs} -> {ss}", fs=fmt(fs), ss=fmt(sorted(ss)))
```

Solution: The seven films selected are: High None; The Best Years of our Lifts; Double Identity; A Star is Bone; Cosiblanket; Mr Deeds goes to Tune; The Maltese Foghorn.

These seven films feature all possible pairings of: Barbara Standup; Fred Astride; Humphrey Bigheart; Joan Crowbar; Judy Garage; James Student; Spencer Treacle.

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