# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1183: Teems of teams

From New Scientist #2339, 20th April 2002 [link]

Our local football team consists of BERT, DAVE, FRED, JACK, JOHN, LEON, MARK, MIKE, NICK, PHIL and STAN. The team is in a large league. On match evenings each team plays in a match and by the end of the season each team has played each of the others once.

I’ve kept a note of last season’s results and I’ve counted up the number of matches in which there was a win for one team or the other, and I’ve also counted the rest, which were draws. I’ve then replaced digits consistently with letters, different letters being used for different digits.

How many matches resulted in a win? [The answer is] WIN.

And in how many was there a tie between two teams? [The answer is] TIE.

How many games were played altogether? The answer is one of our player’s names!

Whose name? And how many teams in the league?

[enigma1183]

### One response to “Enigma 1183: Teems of teams”

1. Jim Randell 25 January 2016 at 8:52 am

The total number of games in a league with n teams is:

t = C(n, 2) = T(n − 1)

In order for each team to play in a game on match day there must be an even number of teams in the league.

This Python program checks possible 4-digit values of t against the possible names. It runs in 157ms.

```from itertools import count
from enigma import C, irange, printf

# possible names
names = ('BERT', 'DAVE', 'FRED', 'JACK', 'JOHN', 'LEON', 'MARK', 'MIKE', 'NICK', 'PHIL', 'STAN')

# assign letters in word <w> to digits in number <n> using mapping <d>
# return (possibly expanded) mapping or None if assignment is not possible
def assign(w, n, d=None):
n = str(n)
if len(n) != len(w): return None
d = (dict() if d is None else dict(d))
for (a, b) in zip(w, n):
if a not in d:
if b in d.values(): return None
d[a] = b
elif d[a] != b: return None
return d

# consider increasing even n
for n in count(2, step=2):
# total number of games
t = C(n, 2)
if t < 1000: continue
if t > 9999: break

# consider possible names
for name in names:
d1 = assign(name, t)
if d1 is None: continue

# find 3 digit numbers for WIN and TIE (that sum to t)
for win in irange(max(100, t - 999), min(999, t - 100)):
tie = t - win
d2 = assign('WIN', win, d1)
if d2 is None: continue
d3 = assign('TIE', tie, d2)
if d3 is None: continue

printf("n={n} t={t} name={name} win={win} tie={tie} {d3}")
```

Solution: The total number of games played corresponds to FRED. There are 58 teams in the league.

The total number of games is FRED=1653. Then we either have WIN=728 and TIE=925 or WIN=928 and TIE=725.

Without the requirement that the number of teams is even we can find additional solutions for n=51 and n=55.