Enigmatic Code

Programming Enigma Puzzles

Enigma 1380: Points for a win

From New Scientist #2540, 25th February 2006

Our local football team consists of five teams and in the course of the season each team plays each of the others once. One point is awarded to each team for a draw and a higher whole number of points (I forget how many) are awarded for a win. Below is part of the league table sometime during the season before all the matches had been completed.

Enigma 1380

The teams are shown in alphabetical order rather than order of merit. No teams have the same number of points. In the table, digits have been replaced consistently by letters, with different letters used for different digits.

How many points for a win? Which team or teams (if any) have the Authors beaten so far?

Enigma 1559 is also called “Points for a win”.


One response to “Enigma 1380: Points for a win

  1. Jim Randell 24 October 2013 at 10:12 am

    This Python program uses the [[ Football() ]] class, recently added to the enigma.py module. It looks at the possibilities for the “Won”, “Lost”, “Drawn”, “Points” and “Position” columns, and then goes on to verify that are possible score lines corresponding to the games that would make the “Goals for” and “Goals against” columns work. It runs in 469ms.

    # there are 10 games in the complete season:
    # AvB, AvC, AvD, AvE, BvC, BvD, BvE, CvD, CvE, DvE.
    # each team plays 4 matches, so the "Won", "Lost" and "Drawn" columns
    # must all be no more than 4, and we have P, O, I, F, A filled out in
    # them and so these must correspond to 0, 1, 2, 3, 4 in some order.
    # also the "Position" column must contain 1, 2, 3, 4, 5 (in some
    # order), as there are no ties on points, but N is already filled out,
    # so N = 5.
    # hence the remaining letters T, S, R, W are 6, 7, 8, 9 in some order.
    # P, O, I are all different and their sum cannot exceed 4, so they are
    # (0, 1, 2) or (0, 1, 3) (in some order), and so (F, A) is what's
    # left: (3, 4) or (2, 4) (in some order), and I, F, A are all drawn
    # matches, so there must be at least 3 drawn matches played.
    # The Authors have 5 points, which can be composed of:
    # 3d + 1w (win is 2 points)
    # 2d + 1w (win is 3 points)
    # 1d + 2w (win is 2 points)
    # 1d + 1w (win is 4 points)
    # 0d + 1w (win is 5 points)
    # so the points for a win is 2, 3, 4, 5.
    # The Bankers have 5 goals against and T > 5 goals for, so they must
    # have won at least one match (P != 0).
    from collections import Counter
    from enigma import Football, diff, printf
    # initialise the game scoring rules
    football = Football(points={ 'w': 2, 'd': 1 })
    N = 5
    # record points for a win and A's victories
    r = Counter()
    # consider possible points for a win X
    for X in (2, 3, 4, 5):
      football = Football(points={ 'w': X, 'd': 1 })
      # consider B's games
      for (ab, bc, bd, be) in football.games(repeat=4):
        # compute won, lost, drawn statistics for B
        tB = football.table([ab, bc, bd, be], [1, 0, 0, 0])
        (P, O, I, S) = (tB.w, tB.l, tB.d, tB.points)
        # P cannot be 0 and P, O, I should be distinct
        if P == 0 or len(set((P, O, I))) != 3: continue
        # remaining digits
        d0 = diff([6, 7, 8, 9], [S])
        if len(d0) != 3: continue
        # remaining games for E
        for (ae, ce, de) in football.games(repeat=3):
          tE = football.table([ae, be, ce, de], [1, 1, 1, 1])
          # check the points
          if tE.points != I: continue
          # remaining games for A
          for (ac, ad) in football.games(repeat=2):
            tA = football.table([ab, ac, ad, ae], [0, 0, 0, 0])
            # check the points
            if tA.points != N: continue
            # remaining game
            for cd in football.games():
              tC = football.table([ac, bc, cd, ce], [1, 1, 0, 0])
              tD = football.table([ad, bd, cd, de], [1, 1, 1, 0])
              # check the remaining drawn figures
              (F, A) = (tC.d, tD.d)
              if set([P, O, I, F, A]) != set([0, 1, 2, 3, 4]): continue
              # and the points for each team must all be different
              points = set([N, S, I, tC.points, tD.points])
              if not(len(points) == 5 and min(points) == I): continue
              # score B's matches
              for T in d0:
                for (AB, BC, BD, BE) in football.scores([ab, bc, bd, be], [1, 0, 0, 0], T, N):
                  # score C's matches
                  for R in diff(d0, [T]):
                    for (AC, CD, CE) in football.scores([ac, cd, ce], [1, 0, 0], R, O):
                      # check E's goals for hasn't exceeded W
                      (fE, aE) = football.goals([BE, CE], [1, 1])
                      W = diff(d0, [T, R])[0]
                      if fE > W: continue
                      # A's victories
                      v = ','.join(t for (t, g) in zip('BCDE', [ab, ac, ad, ae]) if g == 'w')
                      r[(X, v)] += 1
                      printf("AB={ab}:{AB} AC={ac}:{AC} AD={ad} AE={ae} BC={bc}:{BC} BD={bd}:{BD} BE={be}:{BE} CD={cd}:{CD} CE={ce}:{CE} DE={de}\nA={tA}\nB={tB}\nC={tC}\nD={tD}\nE={tE}\nX={X}, P={P} O={O} I={I} S={S} F={F} A={A} T={T} R={R} W={W}\n")
    for ((X, v), n) in r.items():
      printf("win = {X} points, A beat {v} [{n} solutions]")

    Solution: 4 points are awarded for a win. The Authors have beaten The Editors.

    There are many possible score lines for the games, but in all cases the answers to the questions in the problem statement are the same.

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

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

%d bloggers like this: