# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1397: Long third set

From New Scientist #2557, 24th June 2006

A ladies’ match at Wimbledon is won by the first player to win two sets. A set is won by the first player to win 6 games unless the score goes to 5-5; in that case the first or second set is won 7-5 or 7-6 but in the third set play goes on until one player gets 2 games ahead.

Harry and Tom and I each set a puzzle about a ladies’ match in which solvers were told that the third set contained twice as many games as the first set and overall each player won exactly the same number of games.

We also revealed how many games each player had won, because with that information it was possible to deduce with certainty on each puzzle what the score was in each set.

The number of games won overall by each player in Harry’s puzzle was one more than in Tom’s puzzle and two more than in my puzzle.

What was the score in the third set in (a) Harry’s puzzle, (b) Tom’s puzzle, (c) my puzzle?

[enigma1397]

### One response to “Enigma 1397: Long third set”

1. Jim Randell 27 August 2013 at 8:35 am

This Python program runs in 35ms.

```from collections import defaultdict
from enigma import printf

# possible scores for the first two sets
scores = ((6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (7, 5), (7, 6))

# accumulate possible results by number of games won by each player
r = defaultdict(list)

# chose a result for the first set
for r1 in scores:

# the final set has twice the number of games
n = sum(r1)
r3 = (n + 1, n - 1)

# and the winners score in the middle set
for x in (6, 7):
# if the victor won the first set
t = r1[1] + x + r3[1]
r2 = (x, t - (r1[0] + r3[0]))
if r2 in scores:
r[t].append((r1, r2[::-1], r3))
# if the victor lost the first set
t = r1[1] + x + r3[0]
r2 = (x, t - (r1[0] + r3[1]))
if r2 in scores:
r[t].append((r1[::-1], r2, r3))

# remove matches with multiple score lines
for k in list(k for (k, v) in r.items() if len(v) != 1):
del r[k]

# find three consecutive keys with unique match scores
for k in sorted(r.keys()):
if not(k + 1 in r and k + 2 in r): continue
printf("H: {H}, T: {T}, D: {D}", H=r[k + 2][0], T=r[k + 1][0], D=r[k][0])
```

Solution: The third set scores are (a) 10-8 in Harry’s puzzle; (b) 11-9 in Tom’s puzzle; (c) 9-7 in the setter’s puzzle.