# Enigmatic Code

Programming Enigma Puzzles

## Enigma 193: Game, set and match

From New Scientist #1339, 6th January 1983 [link]

This is a letters-for-digits tennis teaser. As always different letters stand consistently for different digits. The final score in our tennis club’s Mens Singles final was AB, CA, DE, FG, FE. Tie breakers occur at 8-8 and are recorded as 9-8 (or 8-9) and are not allowed in the final set. This particular match was very close: at two stages in different sets the eventual winner had match point against him.

Give the score (in numerical form) of the final three sets.

Enigma 101 is called “Game, set & match”.

[enigma193]

### One response to “Enigma 193: Game, set and match”

1. Jim Randell 22 May 2014 at 8:16 am

The Python program examines all possible letter to digit assignments and checks to see if they make a valid match. It runs in 339ms.

```from itertools import permutations
from collections import defaultdict
from enigma import irange, printf

# possible winning scores
scores = [
(6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (7, 5), (8, 6), (9, 7), (9, 8)
]

# check to see if ss is a valid match
def check(*ss):
# index of the final set
n = len(ss) - 1
# we want the match to go to 5 sets
if n != 4: return
# the final set must be won by two games
if abs(ss[n] - ss[n]) != 2: return
# count the sets won
s1 = s2 = 0
# and sets where match point may have been against the winner
m1 = m2 = 0
for (i, (x, y)) in enumerate(ss):
if (x, y) in scores:
# player 1 wins
s1 += 1
# don't win until the last set
if s1 == 3 and i != n: return
# match point against?
if x > 6 and s2 == 2: m1 += 1
elif (y, x) in scores:
# player 2 wins
s2 += 1
# don't win until the last set
if s2 == 3 and i != n: return
# match point against?
if y > 6 and s1 == 2: m2 += 1
else:
# not a valid score
return
# check the winner could have 2 match points against
return (s1 == 3 and m1 == 2) or (s2 == 3 and m2 == 2)

# count the variations on the final 3 sets
r = defaultdict(int)

# consider possible letter to digit assignments
for (A, B, C, D, E, F, G) in permutations(irange(0, 9), 7):
if check((A, B), (C, A), (D, E), (F, G), (F, E)):
r[(D, E, F, G)] += 1
printf("[{A}-{B} {C}-{A} {D}-{E} {F}-{G} {F}-{E}]")

# summarise the resulks
for (k, v) in r.items():
(D, E, F, G) = k
printf("... {D}-{E} {F}-{G} {F}-{E} [{v} ways]")
```

Solution: The score in the final three sets was 5-7, 9-8, 9-7.

The program finds 20 ways to achieve the solution, these correspond to the scores in the first two sets being 6-x and y-6, where (x, y) correspond to all possible 2-permutations from (0, 1, 2, 3, 4), and P(5, 2) = 20.

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