## Brainteaser 1661: Goals galore

**From The Sunday Times, 10th July 1994**

Three football teams played each other once in a tournament. Athletic beat City, City beat Borough, and Borough beat Athletic.

They could not decide which team should receive the trophy since:

Athletic had scored the most goals;

Borough had the best goal average (goals for ÷ goals against)

City had the best goal difference (goals for − goals against)

Fewer than 40 goals were scored in the tournament.

What were the scores in the three games?

This puzzle was included in the book *Brainteasers* (2002, edited by Victor Bryant). The puzzle text above is taken from the book.

[teaser1661]

## Jim Randell 10:39 am

on27 August 2019 Permalink |There are six bounded variables (the number of goals scored by each team in each of the three matches), and the conditions put further constraints on the variables.

I used the

MiniZincsystem to solve the set of constraints, and theminizinc.pylibrary to construct the constraints usingPython.This Python 3 program runs in 228ms.

Solution:The scores in the matches are: A vs B = 3-7; A vs C = 13-12; B vs C = 0-3.In total there were 38 goals scored in the tournament.

The different measures are:

LikeLike

## GeoffR 3:37 pm

on28 August 2019 Permalink |Minizinc found two solutions for me, the first solution looks incorrect as the averages for B and C were the same(7/6 and 14/12, which does not agree with my constraint for goal averages.

The second solution is a correct solution and agrees with the published solution.

LikeLike

## Jim Randell 9:18 am

on29 August 2019 Permalink |@GeoffR: I suspect the second solution comes about because the calculations for “goal average” will be done using floating point numbers. floats are only approximations to real numbers, so if we compare two floats that should be equal, but have been arrived at by different calculations, it is likely that one will compare as larger than the other.

I would change the model to keep things in the integer domain, by replacing constraints of the form:

with the equivalent:

LikeLike

## GeoffR 3:12 pm

on29 August 2019 Permalink |@Jim: Yes, I think you are right as I got a similar second incorrect solution in Python, with a similar approach. For me, it was an unforeseen consequence of using floats instead of integers.

Thanks for the explanation.

LikeLike

## Jim Randell 3:17 pm

on29 August 2019 Permalink |Although in Python you can avoid floats by using the [[

`fractions`

]] module to give an exact representation of rational numbers for the goal averages.LikeLike