PuzzleReels
Sections

The Number Machine

The maths · Episode 27 · 2:40 · gives the answer

The puzzle

A machine spins a number from 1 to 10. You pay a price to play and name a number n from 1 to 10. If the machine spins n you win n dollars, and otherwise you win nothing. What is the fair price to play?

The film says the machine spins "at random", and it does not say "equally likely". Somebody built the machine, and somebody set its odds. That matters, and it is where the puzzle is.

The maths, properly

Write rn for the chance that the machine spins n, with r1+…+r10=1, and qn for the chance that you name n, if you choose by chance. Your expected winnings, in dollars, are

∑n=110nqnrn.

You want this high and the builder wants it low. That is a game between two people, and its fair price is the amount neither can push their way: the best you can guarantee against the worst odds the builder could pick.

First, a machine with equal odds

If every number is equally likely, the machine spins each with chance 110, and the mistakes are easy to make:

  • Averaging the prizes. The prizes 1 to 10 average 5.5 dollars, but you only win a tenth of the time, so that figure forgets the losses.
  • Naming a number at random. Then you win on average 110× the average prize, which is 0.55 dollars.
  • Always naming 10. You win 10 dollars one spin in ten: 1 dollar per spin, the best you can do on an equal machine.

So on an equal machine the fair price would be a dollar, with a player who names 10 every time. But the builder can see that coming.

The builder moves

If you always name 10, the builder turns the dial for 10 down to nothing, and you win nothing. If you then name 9, the builder turns 9 down. Any number you name every time is a number the builder can starve. So you have to name numbers by chance, and the builder has to set odds knowing you will.

Route one: the player's mix

Give the number n a weight in proportion to 1n. The weights must add up to one, so divide by H10:

qn=1/nH10.

To avoid fractions, use the common denominator 2520, which is the smallest number that all of 1 to 10 divide. The tickets are then 2520n, and the total is 7381, so H10=73812520=2.929.

Now whatever odds rn the builder sets, your expected winnings are

∑nn·qn·rn=∑n1H10rn=1H10.

This is because n·qn=1H10 for every n: the weight of a number is exactly cancelled by its prize. The script checks that n×2520n is 2520 for each n, and the sum of the rn is 1 by definition. So you collect 1H10 ≈ 0.3414 dollars on average, whatever the builder does. That is 34 cents, and it is the most you can be sure of.

Route two: the builder's mix

Now the builder's side. Let the machine spin n with chance rn=1/nH10, the same weights. If you name n and stay with it, your expected winnings are n·rn=1H10, the same for every n. Every number is worth the same to you, so whatever you do, you get 1H10 on average, and no better. This is the builder's guarantee.

Here are the odds, with the number of tickets out of 7381 that the film uses:

numberticketschanceworth if named once
1252034.1%0.3414
2126017.1%0.3414
384011.4%0.3414
46308.5%0.3414
55046.8%0.3414
64205.7%0.3414
73604.9%0.3414
83154.3%0.3414
92803.8%0.3414
102523.4%0.3414

The last column is the same for every row, and it is the fair price in dollars.

Why neither side can do better

The two routes meet. You can guarantee 1H10 whatever the builder does, and the builder can hold you to 1H10 whatever you do. So the value of the game is exactly 1H10.

You can also see directly that no mix does better for you. Suppose a mix gave you at least c dollars against every number the builder could favour, which means n·qn≥c for every n. Then qn≥c/n, and adding over all ten numbers,

1=∑qn≥c∑1n=cH10,soc≤1H10.

The script also tries 400,000 spins with a seeded generator, and 50,000 random mixes of the weights: the best any of them could guarantee was 0.2197, below 0.3414.

A worked comparison

Here is what the machines do over 400,000 spins in the script, in dollars per spin. These are simulated and approximate.

playermachineaverage winnings
names 10 every timeequal odds0.9991
names a number at randomequal odds0.5504
mix with weights 1nequal odds0.3485
names 10 every timeodds 1n0.3394
mix with weights 1nodds 1n0.3426

Against equal odds, the person who names 10 every time does best. Against the builder's odds, naming 10 earns the fair value like everything else. If you charged 34 cents against an equal machine, a player who named 10 every time would win about 66 cents a spin from you: that is the cost of setting the price without thinking about the player.

What changes if the numbers change

Another top number. With numbers from 1 to N the fair price is 1HN. It falls slowly as N grows, because HN grows like lnN. For N=1 the price is 1 dollar, for N=2 it is 23, and for the film's 10 it is 0.3414.

Other prizes. If the prize for n is pn, the same argument says to weight n by 1pn, and the fair price is 1÷∑1pn. Here pn=n.

Checking it

scripts/number-machine.mjs asserts the claims below before it writes maths.json, and its --check fails if the file is stale. It checks that:

  • the smallest number that 1 to 10 all divide is 2520, and the tickets 2520n add up to 7381;
  • n times its ticket count is 2520 for every n, so every number is worth the same;
  • the fair value rounds to 34 cents, from 2520 ÷ 7381;
  • on an equal machine the three naive answers are 5.5, 0.55 and 1;
  • the 1n mix against an equal machine is worth exactly the fair value;
  • the seeded simulations of 400,000 spins agree with these figures to within a small tolerance;
  • none of 50,000 random mixes beats the fair value in the worst case.

The proof that no mix does better is the sum above, not the simulation, and it holds for any N.

Where this shows up

  • Minimax and mixed strategies. This is a zero-sum game, and the answer is a mixed strategy: you do best by being unpredictable in a precise proportion. Von Neumann's minimax theorem says such a value exists for every game of this kind.
  • Rock, paper, scissors. Equal chances are the unpredictable mix there, because the three prizes are equal. When the prizes differ, as here, the weights are tilted to cancel them.
  • Harmonic numbers. The sum 1+12+… turns up whenever you weight by the inverse of a size, and it has no tidy closed form.

Try it yourself

1. What is the fair price if the numbers only go from 1 to 3?

H3=1+12+13=116, so the fair price is 611≈0.545 dollars.

2. Why does the weight on 10 have to be smaller than the weight on 1?

The prize on 10 is ten times bigger, so a number that is ten times more likely to be named would be ten times more expensive for the builder. To make every number worth the same, the weights go the other way, so 10 gets a tenth of the weight of 1: 252 tickets against 2520.

3. The builder sets equal odds. What should you name?

Ten, every time. Against equal odds that earns 1 dollar per spin, which is more than the fair price. The fair price is the answer to a builder who is also thinking, not to a careless one.