# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1312: Hampshire v Middlesex

From New Scientist #2470, 23rd October 2004

Next season Hampshire and Middlesex will be among nine English counties in Division 1 of cricket’s league competition and also among the nine in Division 1 of the game’s county championship.

At the end of each season, at present, three counties are relegated to Division 2 of the league and three are relegated to Division 2 of the Championship, but it has been suggested that the number should be cut from three to two in each competition.

If we assume that in both competitions all counties have an equal chance of being relegated, what, as a fraction in its lowest terms, is the probability that in the season after next Hampshire and Middlesex will be in the same division as each other in both competitions if the number of counties relegated from Division 1 of each competition at the end of next season is (a) three, and (b) two?

[enigma1312]

Advertisements

### 2 responses to “Enigma 1312: Hampshire v Middlesex”

1. Jim Randell 3 July 2014 at 7:34 am

This program generates the possible relegation outcomes for the competitions, and counts the cases where, in each division, the teams are either both relegated or both not relegated. It runs in 51ms.

```from itertools import combinations, product
from fractions import Fraction
from enigma import irange, printf

def relegate(s, n):
for r in combinations(s, n):
yield r

# suppose n our of N teams are relegated in each division
def solve(N, n):
# count the number of results we want and the total number
t = r = 0
# identify the teams
ts = set(irange(1, N))
(H, M) = (1, 2)
for (r1, r2) in product(relegate(ts, n), relegate(ts, n)):
t += 1
# check H and M are both relegated or both not relegated
if (H in r1) == (M in r1) and (H in r2) == (M in r2):
r += 1

f=Fraction(r, t)
printf("[{N},{n}] {r} / {t} = {f} = {x}", x=float(f))

solve(9, 3)
solve(9, 2)
```

Solution: (a) 1/4 (= 0.25); (b) 121/324 (≈ 0.3735).

I also coded up a program that runs 100 million random trials. It runs in 4m and verifies the solutions (to 4 decimal places).

2. Jim Randell 3 July 2014 at 7:35 am

Analytically we can see that:

(a) for a division with 9 teams in there are C(9, 3) = 84 ways of choosing the three teams that are relegated, each choice is equally likely.

7 of these choices have both H and M in;

21 of them have H in, but not M, and similarly 21 of them have M in, but not H;

35 of them have neither H nor M in.

The probability of H and M remaining in the same single division (i.e. they are both relegated or both not relegated) is 42/84 = 1/2.

So the probability of them being in the same division in both competitions is 1/2 × 1/2 = 1/4.

(b) for a division with 9 teams in there are C(9, 2) = 36 ways of choosing the two teams that are relegated.

1 of these has both H and M in;

7 of them have H in, but not M, and similarly 7 of them have M in, but not H;

21 of them have neither H nor M in.

The probability of H and M remaining in the same single division is 22/36 = 11/18.

So the probability of them being in the same division in both competitions is 11/18 × 11/18 = 121/324.