# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1265: Going to the dogs

From New Scientist #2421, 15th November 2003 [link]

George was celebrating the fact that on a charity night at his local greyhound track there was no betting tax and the bookmakers’ odds precisely reflected the amounts staked on each dog.

In the first race, the quoted odds-to-one-against each of the six dogs were all different prime numbers. George placed a bet on each dog – £1 on the outsider, higher integer amounts on the others. He then calculated that, irrespective of which dog won, his winnings (including the return of his winning stake) would equal the total amount he staked.

While he was thinking this was a rather pointless exercise, the dog in Trap-1 was withdrawn. George then calculated that if all the bets on that dog (including his) were transferred to the dog in Trap-2, and the odds recalculated accordingly, the odds-to-one-against the five runners would still be different integers.

If this happened, what would be the revised odds for the dog in Trap-2?

[enigma1265]

### 5 responses to “Enigma 1265: Going to the dogs”

1. Jim Randell 7 January 2015 at 9:23 am

This Python program uses the PrimesGenerator() class (originally written for Enigma 1267, but included in the latest version of the enigma.py library) – although it turns out we don’t need to consider very many primes to find the solution. It runs in 48ms.

```# for a stake s and fractional odds f the winnings are: w = s + f * s

from itertools import combinations
from fractions import Fraction as F
from enigma import PrimesGenerator, diff, printf

def main():

primes = PrimesGenerator(100)

# consider the outsider
for x in primes:

# for a 1 pound bet on the outsider the winnings would be ...
w = 1 + x

# find lower primes with integer stakes for the same winning amount
ps = list()
for p in primes:
if not(p < x): break
s = F(w, 1 + p)
if s.denominator == 1:
ps.append((p, int(s)))

# choose 5 of the primes
for t in combinations(ps, 5):

# odds and stakes
(xs, ss) = zip(*(t + ((x, 1),)))

# the sum of the stakes should be the same as the winnings
if sum(ss) == w:
printf("odds = {xs}, stakes = {ss}, winnings = {w}")

# look for pairs of odds which when combined give integer odds
r = False
for ((x1, s1), (x2, s2)) in combinations(zip(xs, ss), 2):
# the odds for the combined stakes are...
f = F(w, s1 + s2) - 1
if f.denominator == 1 and f.numerator not in diff(xs, (x1, x2)):
printf("{x1}-1 and {x2}-1 combine to give new odds of {f}-1 (stake = {s1} + {s2})")
r = True
if r: return

main()
```

Solution: The revised odds for the dog in Trap-2 would 1-1 (evens).

Originally the odds would have been: 2-1, 3-1, 5-1, 7-1, 11-1 and 23-1. So corresponding stakes of £8, £6, £4, £3, £2 and £1 would give winnings of £24 whichever dog won.

One of the 2-1 and 5-1 runners withdraws and the stakes are combined giving odds on the remaining runner of 1-1. (The odds now being 1-1, 3-1, 7-1, 11-1 and 23-1, with corresponding stakes of £12, £6, £3, £2 and £1).

I don’t have a reference for the published solution (I think it would have been published with Enigma 1271 (New Scientist #2429)), but the solution given above seems to be correct.

2. Jim Olson 7 January 2015 at 10:54 pm

I confess my ignorance on dog race betting but how is 7-5 odds satisfying the condition that after trap 1 bets are merged into trap 2 the odds- to- one are still integers?

• Jim Randell 7 January 2015 at 11:00 pm

You’re right – I missed that bit. I’ll have to have another look at how the odds are recalculated.

• Jim Randell 7 January 2015 at 11:32 pm

For some reason I had assumed that the odds were in order, so Trap-1 and Trap-2 were the shortest odds, but it doesn’t say that in the question, so I need to revise my code to look at pairs of odds that combine to give integer fractional odds that don’t clash with the remaining odds. And it turns out there is only one choice: if the the 2-1 runner and the 5-1 runner are combined the resulting odds are 1-1.

I’ll update my code accordingly.

3. Jim Olson 7 January 2015 at 11:11 pm

Isn’t it 1:1 the 2:1 and 5:1 bets are merged?