# Enigmatic Code

Programming Enigma Puzzles

## Enigma 255: Two heads are better than one

From New Scientist #1402, 22nd March 1984 [link]

“Care for a flutter?” Alf asked Bert.

“Suits me,” Bert replied.

“We need a 50p, a 20p, a 10p and a 5p coin. I’ll contribute one of them and you the other three.”

“Then what?”

“We toss all four. If any come up Heads, then whichever of us has the most money (not the most coins) head-side up scoops all four coins. If all four come up Tails, we toss again.”

“OK. Who contributes what?”

“Well,” said Alf, “as I am putting in only one coin, I’ll decide which it is to be.”

Which coin gives the crafty Alf the best bet?

#### News

This puzzle brings the total number of Enigma puzzles on the site to 780. As the final Enigma was #1780, you might think that means there are 1,000 puzzles left to publish. But at Christmas time, especially in the 80’s, multiple puzzles were often published under the same number. (Also, I’ve so far come across three puzzles that are duplicates of already published puzzles). So, my current estimate is that I will need to publish around 1,788 puzzles to have a full archive of Enigma puzzles, so it’ll be a couple of weeks before there are around 1,000 puzzles left to go.

[enigma255]

### 4 responses to “Enigma 255: Two heads are better than one”

1. Jim Randell 2 February 2015 at 9:05 am

This Python program examines the possibilities, and picks the coin that maximizes the winnings. It runs in 36ms.

```from itertools import product
from enigma import Accumulator, printf

# the coins
coins = (50, 20, 10, 5)

# total prize
prize = sum(coins)

# maximise winnings
r = Accumulator(fn=max)

# choose a coin for A
for A in coins:
# count A's winnings and A's losses
Aw = Al = 0
# now consider the possibilities when the coins are tossed
for ts in product('HT', repeat=4):
if 'H' not in ts: continue
# count the total amount heads side up
tA = tB = 0
for (c, t) in zip(coins, ts):
if t == 'H':
if c == A:
tA += c
else:
tB += c
# who won?
if tA > tB:
# A wins the other coins
Aw += prize - A
else:
# A loses his coin to B
Al += A
# outcomes
d = Aw - Al
printf("[A chooses {A}p, wins = {Aw}, losses = {Al}, diff = {d:+d}]")
r.accumulate_data(d, A)

printf("A chooses {r.data}p coin")
```

Solution: Alf should contribute the 20p coin.

2. Julian Gray 2 February 2015 at 3:29 pm

Hi Jim, I’m in trouble with this one! Doing the puzzle longhand, it seems to me that Alf has 8/15 chances to gain 35p if he owns the 50p coin, 4/15 chances to gain 65p if he owns the 20p coin, 2/15 chances to gain 75p if he owns the 10p coin and 1/15 chances to win 80p if he owns the 5p coin. It’s a no-brainer – Alf should hang on to the 50p coin. Please put my mind at rest.

PS Well done with your first 780 puzzles.

• Jim Randell 3 February 2015 at 12:22 am

I’m not an expert on odds and probabilities (you might want to look at [ http://en.wikipedia.org/wiki/Odds ] for more details), but this is how I understand it.

If you contribute the 50p then you are more likely to win the game (as you note), but I think you also need to consider what Alf stands to lose, not just what he stands to win.

If Alf put in a £1 million pound coin instead of the 50p, then he would have a 53% chance of winning 35p, but a 47% chance of losing his £1M. The gambling odds of a win are about 3,000,000 – 1 against.

But if he lets Bert put the £1M in and he only puts in 20p, then he has a 27% chance of winning £1M, and a 73% chance of losing his 20p. The gambling odds of a win are 5,000,000 – 1 on.

As the gambling odds indicate it’s better to go for a 27% chance of winning £1M on a 20p stake than a 53% chance of winning 35p on a £1M stake.

The exaggerated amount makes it a bit easier to see what’s going on. But as the value of the largest coin reduces the gambling odds approach the probability of a win and if we replaced the 50p coin by a 40p coin the gambling odds and the probabilities are the same, so it wouldn’t really matter what coin Alf chose to put in.

With the coins given in the question:

If Alf chooses the 50p coin the probability of a win is 8/15 (about 53%). The gambling odds are 35-50 corresponding to a probability of 10/17 (about 59%). This is more than the actual probability, so the bet is worse than fair.

If Alf chooses the 20p coin the probability of a win is 4/15 (about 27%). The gambling odds are 65-20 corresponding to a probability of 4/17 (about 24%). This is less than the actual probability, so the bet is better than fair.

Choosing 10p the probability of a win is 2/15 (about 13%). The gambling odds are 75-10, corresponding to a probability of 2/17 (about 12%), so the bet is slightly better than fair.

Choosing 5p the probability of a win is 1/15 (about 7%). The gambling odds are 80-5, corresponding to a probability of 1/17 (about 6%), so the bet is slightly better than fair.

The best bet for Alf is to choose 20p.

So much for the theory, I wrote a program to try a million random trials for each choice of coin and the observed outcomes match the calculations:

```import random
from enigma import irange, printf

# number of trials in the simulation
N = 1000000

# the coins
coins = (50, 20, 10, 5)

# total prize
prize = sum(coins)

# choose a coin for A at random
for A in coins:

# count A's winnings and A's losses
Aw = Al = 0

# do N trials
for _ in irange(1, N):

# toss the coins
while True:
ts = tuple(random.choice('HT') for c in coins)
if 'H' in ts: break

# count the total amount heads side up
tA = tB = 0
for (c, t) in zip(coins, ts):
if t == 'H':
if c == A:
tA += c
else:
tB += c
# who won?
if tA > tB:
# A wins the other coins
Aw += prize - A
else:
# A loses his coin to B
Al += A

# outcome
d = Aw - Al
printf("{A} => {v}", v=float(d) / float(N))
```
• Julian Gray 6 February 2015 at 4:11 pm

Thanks Jim – it was me that was the no-brainer!

This site uses Akismet to reduce spam. Learn how your comment data is processed.