Enigmatic Code

Programming Enigma Puzzles

Puzzle 57: Football letters for digits

From New Scientist #1108, 22nd June 1978 [link]

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

But unfortunately the digits have been replaced by letters. Each letter stands for the same digit (from 0 to 9) whenever it appears and different letters stand for different digits.

The table looks like this:

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

Find the score in each match.


One response to “Puzzle 57: Football letters for digits

  1. Jim Randell 10 January 2018 at 9:15 am

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

    Run: [ @repl.it ]

    from enigma import Football, irange, update
    # scoring system
    football = Football(points=dict(w=2, d=1))
    # labels for the teams
    (A, B, C, D) = (0, 1, 2, 3)
    # possible digits
    digits = set(irange(0, 9))
    # columns from the table (without goals for/against)
    table = dict(played='p?k?', w='mp?m', d='??pm', points='?hym')
    # find the match outcomes from the table
    for (ms, d) in football.substituted_table(table):
      # choose a value for x
      for x in digits.difference(d.values()):
        d2 = update(d, dict(x=x))
        # find possible scorelines using teams A, B, D
        for ss in football.substituted_table_goals('xktm', 'xk?y', ms, teams=[A, B, D], d=d2):
          # goals for/against C
          (t, _) = football.goals([ss[(A, C)], ss[(B, C)], ss[(C, D)]], [1, 1, 0])
          if not(t in digits and t not in d2.values()): continue
          # output solution
          football.output_matches(ms, ss, teams='ABCD', d=update(d2, dict(t=t)))

    Solution: The scores in the played matches are: A vs C = 4 – 4; B vs C = 0 – 3; B vs D = 3 – 0; C vs D = 2 – 0.

    The remaining matches (A vs B, A vs D) are not yet played.

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: