Enigmatic Code

Programming Enigma Puzzles

Enigma 1610: Badminton progressions

From New Scientist #2775, 28th August 2010 [link]

A game of badminton is won by the first player to win 21 points, except if the score reaches 20-20, in which case it continues until one player is two points ahead. A match is won by the first player to win two games.

In this match each player won one of the first two games, so that the match required a third game to determine the result. For each of the players, the number of points they won in the three games, taken in game order, formed an arithmetic progression (with a non-zero common difference).

What was the score in the deciding third game?

[enigma1610]

Advertisements

One response to “Enigma 1610: Badminton progressions

  1. jimrandell 2 January 2012 at 2:31 pm

    The following code deals with the four possible cases for scoring the first two matches (with a maximum score less than 100). The code runs in 42ms.

    MAX = 100
    
    # valid game score
    def game(A, B):
      if A < 0 or B < 0: return False
      if A == B: return False
      if A < B: (A, B) = (B, A)
      if A < 21: return False
      if A == 21: return (B < 20)
      if A == B + 2: return True
      return False
    
    # check for valid solutions
    def check(A1, B1, A2, B2, c):
      if A1 == A2 or B1 == B2: return False # differences must be non-zero
      A3 = A2 + (A2 - A1)
      B3 = B2 + (B2 - B1)
      if not game(A3, B3): return False
      print("[{c}] game1={g1} game2={g2} game3={g3} [diff={d}]".format(c=c, g1=(A1, B1), g2=(A2, B2), g3=(A3, B3), d=(A2 - A1, B2 - B1)))
    
    # consider the case A1 > 21, B2 > 21
    def case1():
      for A1 in range(22, MAX):
        B1 = A1 - 2
        for B2 in range(22, MAX):
          A2 = B2 - 2
          check(A1, B1, A2, B2, 1)
    
    # consider the case A1 = 21, B2 > 21
    def case2():
      A1 = 21
      for B1 in range(0, 20):
        for B2 in range(22, MAX):
          A2 = B2 - 2
          check(A1, B1, A2, B2, 2)
    
    # consider the case A1 > 21, B2 = 21
    def case3():
      for A1 in range(22, MAX):
        B1 = A1 - 2
        B2 = 21
        for A2 in range(0, 20):
          check(A1, B1, A2, B2, 3)
    
    # consider case A1 = 21, B2 = 21
    def case4():
      A1 = 21
      for B1 in range(0, 20):
        B2 = 21
        for A2 in range(0, 20):
          check(A1, B1, A2, B2, 4)
    
    case1()
    case2()
    case3()
    case4()
    

    Note that the only valid scores are generated by the first case.

    Solution: The score in the third game is 21:15.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: