# Enigmatic Code

Programming Enigma Puzzles

## Puzzle 30: Football – new method (3 teams)

From New Scientist #1081, 8th December 1977 [link]

A new method to encourage goals in football matches has been suggested. In this method 10 points are awarded for a win, five points for a draw and one point for each goal scored whatever the result of a match.

3 teams, A, B and C are all to play each other once. After some, or perhaps all, of the matches have been played the points were as follows:

A   3
B   7
C  21

Not more than 7 goals were scored in any match.

What was the score in each match?

[puzzle30]

### One response to “Puzzle 30: Football – new method (3 teams)”

1. Jim Randell 30 January 2019 at 8:29 am

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

Run: [ @repl.it ]

from itertools import product
from enigma import irange, Football, printf

# possible scorelines (not more than 7 goals scored in any match)
ss = dict()
ss['w'] = list((x, y) for x in irange(1, 7) for y in irange(0, min(x - 1, 7 - x)))
ss['d'] = list((x, x) for x in irange(0, 3))
ss['l'] = list((x, y) for (y, x) in ss['w'])
ss['x'] = [ None ]

# scoring system (points for goals are added separately)
football = Football(points=dict(w=10, d=5))

# find possible match outcomes
for (AB, AC, BC) in football.games(repeat=3):
A = football.table([AB, AC], [0, 0])
B = football.table([AB, BC], [1, 0])
C = football.table([AC, BC], [1, 1])
if A.points > 3 or B.points > 7 or C.points > 21: continue

for (sAB, sAC, sBC) in product(ss[AB], ss[AC], ss[BC]):
(fA, aA) = football.goals([sAB, sAC], [0, 0])
(fB, aB) = football.goals([sAB, sBC], [1, 0])
(fC, aC) = football.goals([sAC, sBC], [1, 1])
if not(A.points + fA == 3 and B.points + fB == 7 and C.points + fC == 21): continue

printf("AB={AB}:{sAB} AC={AC}:{sAC} BC={BC}:{sBC}")
printf("A={A} f={fA} a={aA}")
printf("B={B} f={fB} a={aB}")
printf("C={C} f={fC} a={aC}")
printf()

Solution: The scores in the played matches are: A vs C = 3-4, B vs. C = 2-2. The A vs B match is not yet played.

This site uses Akismet to reduce spam. Learn how your comment data is processed.