Enigmatic Code

Programming Enigma Puzzles

Enigma 314: Football and addition

From New Scientist #1462, 27th June 1985 [link]

In the following football table and addition sum, letters have been substituted for digits (from 0 to 9). The same letter stands for the same digit wherever it appears, and different letters stand for different digits.

(1) The four teams are eventually going to play each other once, or perhaps they have already done so. With one exception, all the matches were won by a margin of only one goal.

Enigma 314 - A

(Two points are given for a win and one point to each side in a drawn match).

(2)

Enigma 314 - B

Find the scores in the football matches, and write out the addition sum with numbers substituted for letters.

This is the 900th Enigma puzzle to be posted to the site. The archive currently contains Enigmas 1 – 314 (Feb 1979 – Jun 1985) and Enigmas 1199 – 1780 (Aug 2002 – Dec 2013).

[enigma314]

Advertisements

3 responses to “Enigma 314: Football and addition

  1. Jim Randell 9 October 2015 at 9:39 am

    This Python program uses the Football() helper class from the enigma.py library. It runs in 121ms.

    from enigma import Football, irange, printf
    
    # scoring system
    football = Football(points={ 'w': 2, 'd': 1 })
    
    # match outcomes
    for (AB, AC, AD, BC, BD, CD) in football.games(repeat=6):
      C = football.table([AC, BC, CD], [1, 1, 0])
      (g, p, y, m) = (C.played, C.w, C.d, C.points)
      if len(set((g, p, y, m))) != 4: continue
    
      A = football.table([AB, AC, AD], [0, 0, 0])
      B = football.table([AB, BC, BD], [1, 0, 0])
      D = football.table([AD, BD, CD], [1, 1, 1])
    
      # all points are the same
      if not(m == A.points == B.points == D.points): continue
    
      # t is between 1 and 4
      for t in irange(1, 4):
    
        # k = t + t
        k = t + t
        
        if len(set((g, p, y, m, t, k))) != 6: continue
    
        # count the number of scores that differ by more than 1
        def diff(*scores):
          return sum(1 for s in scores if s is not None and abs(s[0] - s[1]) > 1)
    
        # possible outcomes for A's matches
        for (sAB, sAC, sAD) in football.scores([AB, AC, AD], [0, 0, 0], g, t):
    
          # there can be at most 1 match that is won by more than 1 goal
          d1 = diff(sAB, sAC, sAD)
          if d1 > 1: continue
    
          # remaining matches for B
          for (sBC, sBD) in football.scores([BC, BD], [0, 0], t, t, [sAB], [1]):
    
            d2 = d1 + diff(sBC, sBD)
            if d2 > 1: continue
    
            # remaining match for C
            for (sCD,) in football.scores([CD], [0], k, k, [sAC, sBC], [1, 1]):
    
              d3 = d2 + diff(sCD)
              if d3 != 1: continue
    
              # goals for/against for D
              (x, h) = football.goals([sAD, sBD, sCD], [1, 1, 1])
              if len(set((g, p, y, m, t, k, x, h))) != 8: continue
    
              printf("g={g} p={p} y={y} m={m} t={t} k={k} x={x} h={h}")
              printf("AB={AB}:{sAB} AC={AC}:{sAC} AD={AD}:{sAD} BC={BC}:{sBC} BD={BD}:{sBD} CD={CD}:{sCD}")
              printf("A={A}")
              printf("B={B}")
              printf("C={C}")
              printf("D={D}")
              printf()
    

    Solution: (1) The scores in the played matches are: A vs B = 3-2; A vs C = 0-2; B vs C = 2-1; C vs D = 5-6. (2) The sum is: 4 + 4 = 8.

  2. Hugh Casement 9 October 2015 at 10:19 am

    They really were scraping the bottom of the barrel between mid-85 and mid-86.  No fewer than a dozen of the next 50 Enigmata are football puzzles.  How incredibly unimaginative!

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: