Enigmatic Code

Programming Enigma Puzzles

Enigma 350: Oh, careless pen!

From New Scientist #1499, 13th March 1986 [link]

Four football teams (A, B, C and D) are to play each other once. After some of the matches had been played a table was drawn up giving some details of the matches played, won, lost and so on.

Unfortunately, not only had the digits been replaced by letters, but also (Uncle Bungle and his careless pen again!) one of the letters was wrong on one of the occasions on which it appeared — if it appeared more than once.

The table looked like this:

Enigma 350

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

Which letter was wrong? What should it be? Find the score in each match.



One response to “Enigma 350: Oh, careless pen!

  1. Jim Randell 24 June 2016 at 6:34 am

    This program uses the Football() helper class from the enigma.py library, and makes particular use of the Football.substitute_table*() solvers. It runs in 53ms.

    from enigma import Football, printf
    # the error is in the goals for / goals against columns, as they
    # should sum to the same value, but:
    # (d + t + r + d) - (h + d + d + t) = r - h
    # so we can proceed with the rest of the table
    # scoring system
    football = Football(points={ 'w': 2, 'd': 1 })
    # indices and names for the teams
    teams = (0, 1, 2, 3)
    names = 'ABCD'
    # solve the table
    for (matches, d) in football.substituted_table({ 'played': '?xh?', 'w': '??d?', 'd': '?txx', 'points': 't?rh' }):
      # three of the goals for / goals against rows must be correct
      (gf, ga) = ('dtrd', 'hddt')
      for t in teams:
        # and determine the scores in the matches
        for scores in football.substituted_table_goals(gf, ga, matches, d=d, teams=teams[:t] + teams[t + 1:]):
          printf("error in row {i} (team {t})", i=t + 1, t=names[t])
          # and determine the actual goals for team t
          ms = list(tuple(sorted((t, x))) for x in teams if x != t)
          g = football.goals((scores[m] for m in ms), (m.index(t) for m in ms))
          printf("(f, a) = {g} (not {ng})\n", ng=(d[gf[t]], d[ga[t]]))
          # output all fixtures
          football.output_matches(matches, scores, teams=names, d=d)

    Solution: The error in the table is in the “goals against” column for team “A”. The letter should be “r” (5) not “h” (3). The scores in the played matched are: A vs C = 2 – 3; A vs D = 0 – 2; B vs C = 0 – 2; C vs D = 0 – 0. The matches A vs B and B vs D have not yet been played.

    The values of the letters are: d = 2; h = 3; r = 5; t = 0; x = 1.

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: