Enigmatic Code

Programming Enigma Puzzles

Puzzle 87: Football: letters for digits

From New Scientist #1139, 25th January 1979 [link]

Three football teams (A, B & C) are to play each other once. After some (or perhaps all) of the games had been played a table giving some details of the matches played, won, lost and so on was drawn up. But unfortunately Uncle Bungle has been at it again and he decided to replace the digits 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 looked like this:

Puzzle 87

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

Find the score in each match.

[puzzle87]

One response to “Puzzle 87: Football: letters for digits

  1. Jim Randell 7 December 2016 at 7:35 am

    I used the [[ Football() ]] helper class from the enigma.py library to solve this one.

    This Python program runs in 60ms.

    from enigma import Football, irange, update
    
    # scoring system
    football = Football(points={ 'w': 2, 'd': 1 })
    
    # solve the table
    for (matches, d) in football.substituted_table({ 'played': '?k?', 'l': 'r??', 'd': '?d?', 'points': 'p?d' }):
    
      # consider possible values for m (it must be the same parity as p) and x
      p = d['p']
      for m in irange(p % 2, 9, step=2):
        h = (m + p) // 2
    
        for x in irange(0, 9):
          d2 = update(d, zip('mhx', (m, h, x)))
    
          # check all values are distinct
          if len(set(d2.values())) != 7: continue
    
          # determine the scores in the matches
          for scores in football.substituted_table_goals('xmp', 'hxh', matches, d=d2):
    
            # output the matches
            football.output_matches(matches, scores, teams='ABCD', d=d2)
    

    Solution: The scores in the matches are: A v B = 6-5; A v C = 3-1; B v C = 3-3.

    The values for the letters are: d=1, h=6, k=2, m=8, p=4, r=0, x=9.

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: