Enigmatic Code

Programming Enigma Puzzles

Enigma 219: Matchwork, patchwork

From New Scientist #1365, 7th July 1983 [link]

Five football teams — ABCD and E — are all to play each other once. After some of the matches had been played a table giving some details of the matches played, won lost etc, looked like this:

Enigma 219

Find the score in each match so far played.

Note: I am waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment.

[enigma219]

Advertisements

3 responses to “Enigma 219: Matchwork, patchwork

  1. Jim Randell 3 September 2014 at 12:23 pm

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

    from enigma import Football, printf
    
    # there are 10 possible games: AvB AvC AvD AvE BvC BvD BvE CvD CvE DvE
    
    # initialise the (assumed) scoring rules
    football = Football(points={ 'w': 2, 'd': 1 })
    
    # consider the games for C
    for (ac, bc, cd, ce) in football.games(repeat=4):
      C = football.table([ac, bc, cd, ce], [1, 1, 0, 0])
      if not(C.played == 2 and C.d == 1): continue
    
      # and remaining games for A
      for (ab, ad, ae) in football.games(repeat=3):
        A = football.table([ab, ac, ad, ae], [0, 0, 0, 0])
        if not(A.w == 0 and A.d == 2): continue
    
        # remaining games for E
        for (be, de) in football.games(repeat=2):
          E = football.table([ae, be, ce, de], [1, 1, 1, 1])
          if not(E.played == 2): continue
    
          # remaining game
          for bd in football.games():
            B = football.table([ab, bc, bd, be], [1, 0, 0, 0])
            D = football.table([ad, bd, cd, de], [1, 1, 1, 0])
            if not(B.d == 0 and D.d == 0): continue
    
            # compute possible scorelines for A
            for (AB, AC, AD, AE) in football.scores([ab, ac, ad, ae], [0, 0, 0, 0], 3, 3):
    
              # possible scorelines for C
              for (BC, CD, CE) in football.scores([bc, cd, ce], [1, 0, 0], 2, 4, [AC], [1]):
    
                # possible scorelines for D
                for (BD, DE) in football.scores([bd, de], [1, 0], 1, 1, [AD, CD], [1, 1]):
    
                  # check goals against B (so far) is 0
                  (fB, aB) = football.goals([AB, BC, BD], [1, 0, 0])
                  if aB != 0: continue
    
                  # the remaining match is BvE, B has 0 goals against so (if
                  # the match is played) the score can only be x-0, and x
                  # contributes to the "goals for" column (for B) and the
                  # "goals against" column (for E) so we can't determine it
                  if be == 'x':
                    BE = None
                  elif be == 'd':
                    BE = (0, 0)
                  elif be == 'w':
                    BE = ('?', 0)
    
                  printf("AB={ab}:{AB} AC={ac}:{AC} AD={ad}:{AD} AE={ae}:{AE} BC={bc}:{BC} BD={bd}:{BD} BE={be}:{BE} CD={cd}:{CD} CE={ce}:{CE} DE={de}:{DE}\nA={A}\nB={B}\nC={C}\nD={D}\nE={E}\n")
    

    Solution: The scores in the matches played so far are – A vs. C, 2 – 2; A vs. E, 1 – 1; B vs. C, 2 – 0; B vs. D, 1 – 0; D vs. E, 1 – 0.

    The matches A vs. B, A vs. D, B vs. E, C vs. D and C vs. E have not yet been played.

  2. Jim Olson 3 September 2014 at 6:38 pm

    The table did not come through. Maybe it is an internet issue.

  3. Jim Olson 3 September 2014 at 6:39 pm

    It was blank but has now come through. I will be more patient.

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: