Enigmatic Code

Programming Enigma Puzzles

Enigma 1472: Wrong calls

From New Scientist #2633, 8th December 2007

In tennis a set is won by the first player to win 6 games unless the score reaches 5-5; in that case the set is won 7-5 or 7-6.

At Wimbledon the first batch of tennis balls is used for the warm-up and the first seven games; each subsequent batch of balls is used for nine games.

This means that during the second set there are certain scores at which it is impossible for a new batch of balls to be required, whatever the score in the first set may have been.

Dick wants to be a Wimbledon umpire and practiced by umpiring the match between Harry and Tom. But three times during the second set he called for new balls at scores at which it is impossible for them to be required.

The number of games that Tom had won in the second set was the same when Dick made the third of those calls as when Dick made the second of them.

What was the score in the second set at the time of (a) the first wrong call, (b) the third wrong call? Give each answer in the form xy, Harry’s score first.



One response to “Enigma 1472: Wrong calls

  1. Jim Randell 20 January 2013 at 11:38 am

    The following Python program runs in 40ms.

    from itertools import combinations, permutations
    from enigma import irange, printf
    # determine possible scores in a set, and winning scores
    (scores, wins) = (set(), set())
    for n in irange(0, 13):
      for a in irange(min(n, 7), n // 2, -1):
        b = n - a
        if b > a: continue
        if a == 7 and b < 5: continue
        scores.add((a, b))
        if (a == 6 and b < 5) or a == 7: wins.add((a, b))
    # record possible second set scores when new balls are needed
    nb = set()
    # choose a score for the first set
    for s1 in wins:
      g1 = sum(s1)
      # now consider possible scores in the second set
      for s2 in scores:
        g = g1 + sum(s2)
        # new balls?
        if (g - 7) % 9 == 0: nb.add(s2)
    # so the impossible scores for new balls in the second set are...
    imp = scores.difference(nb)
    printf("[impossible = {imp}]")
    # we need to find a sequence of three such scores
    for s in combinations(imp, 3):
      # sort them by the number of games played
      (s1, s2, s3) = sorted(s, key=sum)
      # ignore sequences that wouldn't get to the third item
      if s1 in wins or s2 in wins: continue
      # must have the same number of won games for Tom is s2 and s3
      for T2 in set(s2).intersection(s3):
        # Harry's wins are the other one in the second and third items
        H2 = s2[int(T2 == s2[0])]
        H3 = s3[int(T2 == s3[0])]
        # Harry's wins can't have decreased
        if H2 > H3: continue
        # consider the wins in the first item of the sequence
        for (T1, H1) in permutations(s1):
          # neither Tom's wins nor Harry's wins can have decreased
          if T1 > T2 or H1 > H2: continue
          # so the scores that the calls were made at were...
          printf("calls: [1st] {H1}-{T1}, [2nd] {H2}-{T2}, [3rd] {H3}-{T2}")

    Solution: The scores are: (a) 0-2; (b) 6-5.

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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


Connecting to %s

%d bloggers like this: