Enigmatic Code

Programming Enigma Puzzles

Enigma 478: Football, addition, letters and a twist

From New Scientist #1629, 8th September 1988 [link]

In both the football league table and addition sum below, letters have been substituted for digits. Each letter stands or should stand for a different digit (from 0 to 9), and different letters should stand for different digits. And so they do except for the fact that one of the letters is incorrect on one of the occasions on which it appears (if indeed it appears more than once).

The three teams are eventually going to play each other once, or perhaps they have already done so.

Enigma 478

Which letter was wrong? What should it be?

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


One response to “Enigma 478: Football, addition, letters and a twist

  1. Jim Randell 10 December 2018 at 8:44 am

    There are at most 3 matches played (A v B, A v C, B v C).

    If we suppose the “played” and “points” columns are correct.

    If no matches had been played, all the values would be 0, so there would be more than one mistake in the table (and in particular the columns we are supposing are correct).

    If all matches had been played, then every value in the “played” column would be 2, so there would be a mistake in the “played” column.

    If only one match had been played then k and g would be 0 and 1 (in some order). But they appear in the other order in the “points” column. So one team would have to have played 0 matches and gained 1 point. This is impossible.

    If two matches had been played. Then one team has played 2 matches, and the other teams have played 1 match each. So k and g would be 1 and 2 in some order. In each of the 2 matches 2 points are awarded, so the sum of the “points” column is 4, so m would have to be 1, but we know one of g or k is 1. So this is not possible either.

    So there is no scenario where both the “played” and “points” columns are correct, so the error must be in one of these columns.

    This Python program uses the [[ Football() ]] helper class from the enigma.py to find the erroneous entry in the table, and the outcomes of the matches. It runs in 83ms.

    Run: [ @repl.it ]

    from itertools import permutations
    from enigma import Football, irange, chunk, seq_all_different, update, printf
    # scoring system
    football = Football(games='wdlx', points=dict(w=2, d=1))
    # the columns of the table (without the goals columns)
    #      played   points   won    lost    drawn
    table = "kg?" + "gkm" + "??m" + "m??" + "??k"
    # possible digits
    digits = set(irange(0, 9))
    # remove one of the entries from the played/points columns
    for i in (0, 1, 3, 4, 5):
      t = table[:i] + '?' + table[i + 1:]
      # split out the revised table into columns
      t = dict(zip(('played', 'points', 'w', 'l', 'd'), chunk(t, 3)))
      for (m, d) in football.substituted_table(t):
        # now solve the sum
        ds = digits.difference(d.values())
        for (h, x) in permutations(ds, 2):
          (p, t) = (h + x, 2 * x)
          vs = (h, x, p, t)
          if not(seq_all_different(vs) and ds.issuperset(vs)): continue
          # determine possible scorelines (using the goals columns)
          d1 = update(d, 'hxpt', vs)
          for s in football.substituted_table_goals('xpx', 'htx', m, d1):
            # output solution
            printf("[error @ i={i} is {v}]", v=table[i])
            football.output_matches(m, s, teams="ABC", d=d1)

    Solution: The points entry for C should be k (= 1), not m (= 0). The scores in the matches are: A v B = 4 – 3; A v C = not played; B v C = 4 – 4. The addition sum is: 3 + 4 = 7.

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: