# Enigmatic Code

Programming Enigma Puzzles

## Enigma 219: Matchwork, patchwork

From New Scientist #1365, 7th July 1983 [link]

Five football teams — ABCD and E — are all to play each other once. After some of the matches had been played a table giving some details of the matches played, won lost etc, looked like this:

Find the score in each match so far played.

Note: I am waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment.

[enigma219]

### 3 responses to “Enigma 219: Matchwork, patchwork”

1. Jim Randell 3 September 2014 at 12:23 pm

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

```from enigma import Football, printf

# there are 10 possible games: AvB AvC AvD AvE BvC BvD BvE CvD CvE DvE

# initialise the (assumed) scoring rules
football = Football(points={ 'w': 2, 'd': 1 })

# consider the games for C
for (ac, bc, cd, ce) in football.games(repeat=4):
C = football.table([ac, bc, cd, ce], [1, 1, 0, 0])
if not(C.played == 2 and C.d == 1): continue

# and remaining games for A
for (ab, ad, ae) in football.games(repeat=3):
A = football.table([ab, ac, ad, ae], [0, 0, 0, 0])
if not(A.w == 0 and A.d == 2): continue

# remaining games for E
for (be, de) in football.games(repeat=2):
E = football.table([ae, be, ce, de], [1, 1, 1, 1])
if not(E.played == 2): continue

# remaining game
for bd in football.games():
B = football.table([ab, bc, bd, be], [1, 0, 0, 0])
D = football.table([ad, bd, cd, de], [1, 1, 1, 0])
if not(B.d == 0 and D.d == 0): continue

# compute possible scorelines for A
for (AB, AC, AD, AE) in football.scores([ab, ac, ad, ae], [0, 0, 0, 0], 3, 3):

# possible scorelines for C
for (BC, CD, CE) in football.scores([bc, cd, ce], [1, 0, 0], 2, 4, [AC], [1]):

# possible scorelines for D
for (BD, DE) in football.scores([bd, de], [1, 0], 1, 1, [AD, CD], [1, 1]):

# check goals against B (so far) is 0
(fB, aB) = football.goals([AB, BC, BD], [1, 0, 0])
if aB != 0: continue

# the remaining match is BvE, B has 0 goals against so (if
# the match is played) the score can only be x-0, and x
# contributes to the "goals for" column (for B) and the
# "goals against" column (for E) so we can't determine it
if be == 'x':
BE = None
elif be == 'd':
BE = (0, 0)
elif be == 'w':
BE = ('?', 0)