# Enigmatic Code

Programming Enigma Puzzles

## Enigma 314: Football and addition

From New Scientist #1462, 27th June 1985 [link]

In the following football table and addition sum, letters have been substituted for digits (from 0 to 9). The same letter stands for the same digit wherever it appears, and different letters stand for different digits.

(1) The four teams are eventually going to play each other once, or perhaps they have already done so. With one exception, all the matches were won by a margin of only one goal.

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

(2)

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

This is the 900th Enigma puzzle to be posted to the site. The archive currently contains Enigmas 1 – 314 (Feb 1979 – Jun 1985) and Enigmas 1199 – 1780 (Aug 2002 – Dec 2013).

[enigma314]

### 3 responses to “Enigma 314: Football and addition”

1. Jim Randell 9 October 2015 at 9:39 am

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

```from enigma import Football, irange, printf

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

# match outcomes
for (AB, AC, AD, BC, BD, CD) in football.games(repeat=6):
C = football.table([AC, BC, CD], [1, 1, 0])
(g, p, y, m) = (C.played, C.w, C.d, C.points)
if len(set((g, p, y, m))) != 4: continue

A = football.table([AB, AC, AD], [0, 0, 0])
B = football.table([AB, BC, BD], [1, 0, 0])
D = football.table([AD, BD, CD], [1, 1, 1])

# all points are the same
if not(m == A.points == B.points == D.points): continue

# t is between 1 and 4
for t in irange(1, 4):

# k = t + t
k = t + t

if len(set((g, p, y, m, t, k))) != 6: continue

# count the number of scores that differ by more than 1
def diff(*scores):
return sum(1 for s in scores if s is not None and abs(s[0] - s[1]) > 1)

# possible outcomes for A's matches
for (sAB, sAC, sAD) in football.scores([AB, AC, AD], [0, 0, 0], g, t):

# there can be at most 1 match that is won by more than 1 goal
if d1 > 1: continue

# remaining matches for B
for (sBC, sBD) in football.scores([BC, BD], [0, 0], t, t, [sAB], [1]):

d2 = d1 + diff(sBC, sBD)
if d2 > 1: continue

# remaining match for C
for (sCD,) in football.scores([CD], [0], k, k, [sAC, sBC], [1, 1]):

d3 = d2 + diff(sCD)
if d3 != 1: continue

# goals for/against for D
(x, h) = football.goals([sAD, sBD, sCD], [1, 1, 1])
if len(set((g, p, y, m, t, k, x, h))) != 8: continue

printf("g={g} p={p} y={y} m={m} t={t} k={k} x={x} h={h}")