# Enigmatic Code

Programming Enigma Puzzles

## Enigma 346: Alphabetical goals

From New Scientist #1495, 13th February 1986 [link]

Five football teams, A, B, C, D and E, are to play each other once. After some of the games had been played a table was drawn up giving some details of the matches played, won, lost etc.

Unfortunately, the digits had been replaced by letters. Each letter stood for the same digit (from 0 to 9) wherever it appeared, and different letters stood from different digits.

The table looked 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.

[enigma346]

### One response to “Enigma 346: Alphabetical goals”

1. Jim Randell 27 May 2016 at 8:38 am

This program uses the Football() helper class (and the new Football.substituted_table*() solvers) from the enigma.py library. It runs in 370ms.

```from enigma import Football

# scoring system
football = Football(points={ 'w': 2, 'd': 1 })

# labels for the teams
(A, B, C, D, E) = (0, 1, 2, 3, 4)

# find possible match outcomes
for (matches, d) in football.substituted_table({ 'played': 'm??a?', 'l': '?hpg?', 'd': 'p???g', 'points': 'm??dg' }):

# find possible score lines for teams other than D
for scores in football.substituted_table_goals('ggdxh', 'adpyh', matches, d, teams=[E, B, C, A]):

# compute the values of x and y
(x, y) = football.goals([scores[(A, D)], scores[(B, D)], scores[(C, D)], scores[(D, E)]], [1, 1, 1, 0])
if x > 9 or y > 9 or x == y or x in d.values() or y in d.values(): continue
d.update({ 'x': x, 'y': y })

# output the solution
football.output_matches(matches, scores, teams='ABCDE', d=d)
```

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

The following matches are not yet played: A vs C; A vs E; B vs E; C vs E.