Enigmatic Code

Programming Enigma Puzzles

Tantalizer 485: Screen test

From New Scientist #1036, 27th January 1977 [link]

Our local cinema has been split into three and the manager has to pick a balanced programme from a list of options supplied by head office. At present he is busy arranging the two weeks after Easter.

He works in whole weeks and here are his thoughts so far. “Sizzling Sixteen” will be shown for at least one week and the Russian “Hamlet” for exactly one week. If “Hamlet” is on for the second week, it will be teamed with that award-winning Western “Dead Fish Gulch” and if  “Hamlet” is on for the first, it will share the billing with “Sizzling Sixteen”. “Tarzan Meets Winnie the Pooh” is a must for the first week, if “Sizzling Sixteen” is screened for the second, and a must for the second, if “Dead Fish Gulch” is not shown in the first. If “Sizzling Sixteen” is to be in the first week, “Dead Fish Gulch” will be in the second. It would be a disaster to screen both “Dead Fish Gulch” and “Sizzling Sixteen” in the first week or both “Dead Fish Gulch” and “Tarzan Meets Winnie the Pooh” in the second.

If the worst comes to the worst, he can fill in with “The Resurrection” in either week or both.

Which three films should he pick for each week?

[tantalizer485]

One response to “Tantalizer 485: Screen test”

1. Jim Randell 12 April 2017 at 8:28 am

This problem is straightforward to tackle manually. And programatically it doesn’t take much to check all the possibilities to find those which satisfy the required conditions.

This Python program runs in 38ms.

```from itertools import combinations, product
from enigma import printf

# logical implication: "if p then q", "p implies q"
implies = lambda p, q: not(p) or q

# the films
films = (D, H, R, S, T) = 'DHRST'

# choose the films for both weeks
for (w1, w2) in product(combinations(films, 3), repeat=2):

# check the statements
if all((

# "S will be shown for at least one week"
(S in w1) + (S in w2) > 0,

# "H will be shown for exactly one week"
(H in w1) + (H in w2) == 1,

# "if H is shown in week 2, then D is also shown in week 2"
implies(H in w2, D in w2),

# "if H is shown in week 1, then S is also shown in week 1"
implies(H in w1, S in w1),

# "T will be shown in week 1 if S is shown in week 2"
implies(S in w2, T in w1),

# "T will be shown in week 2 if D is not shown in week 1"
implies(D not in w1, T in w2),

# "if S is shown in week 1, then D is shown in week 2"
implies(S in w1, D in w2),

# "D and S cannot be shown together in week 1"
not(D in w1 and S in w1),

# "D and T cannot be shown together in week 2"
not(D in w2 and T in w2),

)):
printf("w1 = {w1}, w2 = {w2}")
```

Solution: Week 1: “Dead Fish Gulch”, “The Resurrection”, “Tarzan Meets Winnie The Pooh”; Week 2: “Dead Fish Gulch”, “Hamlet”, “Sizzling Sixteen”.