# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1422: Incentive

From New Scientist #2582, 16th December 2006

The four football teams, Magdala, Nazareth, Sepphoris and Tiberias, play each other once a season, with 2 points for a win and 1 for a draw. At the end of the season there is a table which orders the teams by points scored, and teams with equal points are bracketed together.

The prize money, in drachmas, is 40, 30, 20 and 10 for the teams in 1st, 2nd, 3rd, 4th places respectively; when teams are bracketed they divide the total money for their places evenly between themselves.

One match is played each week with the first four being MvS, NvT, MvT, NvS. After the fourth match, Jesus works out the points totals situation (PTS) and uses it to determine whether the fifth match should be MvN or SvT. He makes the choice so that in the sixth match both teams have a financial incentive to play hard. For example, if the PTS is M3, N2, S1, T2 then whichever is the fifth match, both teams in the sixth will play hard.

For how many PTSs is it essential to have MvN as the fifth match?

[enigma1422]

### One response to “Enigma 1422: Incentive”

1. Jim Randell 11 June 2013 at 8:11 am

I found the wording in this problem confusing. I was on the verge of marking the puzzle as “flawed”.

Initially I thought that by “play hard” the setter would mean “play to win”. i.e. the prize money a team would get by winning the match was better than they would get for a draw. But if you go down that route it’s not possible to always choose a 5th match such that both teams are required to “play hard” in the final match. (You can relax what “essential” means, but that still won’t lead you to the required answer).

Instead, by interpreting “play hard” to mean “play to not lose”, we can always choose a 5th match such that both teams in the final match are required to “play hard” (i.e. try not to lose), and this route leads to the required answer.

This Python program runs in 44ms.

```from itertools import product
from enigma import printf

# possible points
pts = ((2, 0), (1, 1), (0, 2))

# winnings for points <t> given the other teams points are <rest>
def winnings(t, *rest):
# how many of the other teams have fewer points
f = sum(1 for x in rest if x < t)
# how many of the other teams have the same points
s = sum(1 for x in rest if x == t)
# so the winnings for <t> are...
return 10 * (f + 1) + 5 * s

# does team <t> against <u> have an incentive to win? (the other teams being <x> and <y>)
def incentive(t, u, x, y):
# a team has an incentive to play if they would get more money by winning than by losing
return winnings(t + 2, u, x, y) > winnings(t, u + 2, x, y)

(n, t) = (0, 0)
for (MS, NT, MT, NS) in product(pts, repeat=4):
# scores after 4 matches
(M, N, S, T) = (MS[0] + MT[0], NT[0] + NS[0], MS[1] + NS[1], NT[1] + MT[1])
t += 1

# if SvT is played 5th, would that mean one of M and N would have no incentive in some of the possible outcomes?
if not all(incentive(M, N, S + p, T + q) and incentive(N, M, S + p, T + q) for (p, q) in pts):

# so if MvN is the 5th match check both S and T have an incentive in the final match
assert all(incentive(S, T, M + p, N + q) and incentive(T, S, M + p, N + q) for (p, q) in pts)

# this is a case where it is "essential" that MvN is the 5th match
n += 1

printf("{n} / {t}")
```

Solution: It is essential to have MvN as the fifth match in 10 (out of 81) cases.