Enigmatic Code

Programming Enigma Puzzles

Enigma 1665: Football league

From New Scientist #2831, 24th September 2011 [link]

My local football league has five teams, which each play each of the other teams twice. Three points are given for a win, and 1 point for a draw. At the end of the season, all five teams tied with the same number of points, so they were ordered by goal difference, which gave a clear winner. The team that drew the most games also won a game against the team that came top of the league.

How many games did the team that came top of the league win, draw and lose?

[enigma1665]

Advertisements

One response to “Enigma 1665: Football league

  1. Jim Randell 4 December 2011 at 12:02 am

    The following Python code runs in 31ms.

    from itertools import product
    
    # there are twenty games, each game is either won (and lost), or drawn
    # if 20 games are drawn there are 40 total points
    # if 20 games are won/lost there are 60 total points
    # also all 5 teams scored the same number of points so the total number
    # of points must be: 40, 45, 50, 55, 60
    # we know some games were drawn (so the total is not 60)
    # and not all games were drawn (so the total is not 40)
    # so the total is 45, 50, 55 and each teams points are 9, 10, 11
    
    pt = { 9: [], 10: [], 11: [] }
    
    for w in range(8+1):
      for d in range(8-w+1):
        p = 3 * w + d
        if p not in (9, 10, 11): continue
        l = 8 - w - d
        pt[p].append((w, d, l))
    
    ss = set()
    for (p, scores) in pt.iteritems():
      for s in product(scores, repeat=5):
        w = sum(i[0] for i in s)
        d = sum(i[1] for i in s)
        l = sum(i[2] for i in s)
        if not(w == l): continue
        if not(w + l + d == 40): continue
        ss.add(tuple(sorted(s)))
    
    for s in ss:
      # _the_ team that drew the most games...
      s = sorted(s, key = lambda i: i[1], reverse=True)
      if s[0][1] == s[1][1]: continue
      # ... also won a game ...
      if s[0][0] < 1: continue
    
      print(s)
    

    From looking at the result(s) the team with the most draws (1w7d0l) also won a game against the team at the top of the league.

    Since they have 7 draws and 1 win that means they have 2 draws against each of the teams with 2w4d2l and 1w1d against the team with 3w1d4l which must be the team at the top of the league.

    Solution: The team at the top of the league won 3 games, drew 1 game and lost 4 games.

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: