PuzzleReels
Sections

The Submarine

The maths · Episode 8 · 2:39 · gives the answer

The puzzle

A submarine starts at an unknown whole number on a line and moves the same unknown whole number of places every turn: forwards, backwards, or not at all. Once a turn you may drop a depth charge on one whole number. A hit sinks it, and a miss tells you nothing.

Can you guarantee to sink it?

The maths, properly

Count the turns from 1. A submarine that started at a with speed v is at a+vt on turn t. Call it the submarine (a,v).

Since a miss tells you nothing, nothing you learn can change what you do next: until the hit, every hunt goes the same way. So a strategy is just a sequence of positions d1,d2,d3,… written down in advance, and the question is whether some sequence meets every line a+vt.

Why sweeping fails

This is the film's first route, and the point is that it is not slow but dead. Take any turn t, any position p, and any misses at all on the turns before. A submarine that is at p now with speed v was at p−v(t−s) on an earlier turn s. A miss on d at turn s rules that submarine out only if p−v(t−s)=d, that is, only if

v=p−dt−s

which is one speed at most. So t−1 misses rule out at most t−1 of the infinitely many speeds that bring a submarine to p by now, and every position is still possible. Ten charges a turn change nothing: they rule out at most 10(t−1) speeds.

0123456−24−1201224 start turn
At turn 6, one straight-line submarine on every position from −24 to 24

That is the film's fan. At turn 6, one straight line ends on each position from −24 to 24. Each miss can cross off at most one line through each position, and there are infinitely many lines through each.

Proof one: walk the grid

This is the film's second route. The unknown is not a place but a pair of whole numbers, and pairs are the points of a grid. Walk the grid in a square spiral, right one, up one, left two, down two, right three, and so on:

(0,0),(1,0),(1,1),(0,1),…

The walk finishes the 3×3 square round the origin in 9 steps, the 5×5 in 25, and the (2r+1)×(2r+1) in (2r+1)2, so every pair comes up, and exactly once.

On turn t, take the t-th pair on the walk, (at,vt), and drop where that submarine would be:

dt=at+vtt

If the real submarine is the t-th pair, it is at at+vtt on turn t, which is where the charge is. Every pair has a place on the walk, so every submarine is sunk on the turn of its place, or earlier if some other pair's charge happens to land on it first. The place is a deadline, not an average.

Proof two: a formula instead of a picture

The spiral is a drawing. Cantor's pairing is a formula, and it needs no drawing at all. First turn the whole numbers into 0,1,2,…:

0,−1,1,−2,…⟼0,1,2,3,…

which is z↦2z for z≥0 and z↦−2z−1 for z<0. Write z~ for the result. Then give (a,v) the place

(a~+v~)(a~+v~+1)2+v~+1

which counts along the diagonals a~+v~=0,1,2,… one after another. Every pair gets one place and every place one pair, and the hunter is one line of arithmetic: on turn t, find the pair whose place is t, and drop where it is.

The proof is the same and so is the guarantee; only the deadlines move. The film's submarine (3,−2) has place 49 on this list instead of 26, and in fact it is sunk on turn 2, by luck: turn 2 reads off (−1, 0), whose charge lands on −1, and (3,−2) is at −1 on turn 2 as well.

Proof three: any list will do

Neither proof used the fact that the paths are straight. Suppose the submarine follows one of a family of paths that can be put in a list, f1,f2,f3,…, each saying where it is on every turn. Drop on

h(t)=ft(t)

the t-th path's position on turn t. If the submarine follows fk, then on turn k the charge is at fk(k), and so is the submarine. That is the whole proof, and the film's case is ft(s)=at+vts. Draw a table with one row for each path and one column for each turn, and the hunter is its diagonal. The next film, The Deep, turns this argument round on itself.

A worked case: the film's hunt

The film follows the submarine that starts at 3 and moves −2 a turn. On the spiral (3,−2) is pair 26, so its deadline is turn 26: 25 misses, then a hit at −49.

26 123925−303−303 start a speed v
The spiral reaches (3, −2) on turn 26
01326320−49 turn
The 25 misses, the submarine's line, and the hit at −49 on turn 26
The 26 turns, one by one
The film's hunt: on turn t, drop where the t-th pair would be
TurnPair read offDrop onThe submarine is at
1(0, 0)01
2(1, 0)1−1
3(1, 1)4−3
4(0, 1)4−5
5(−1, 1)4−7
6(−1, 0)−1−9
7(−1, −1)−8−11
8(0, −1)−8−13
9(1, −1)−8−15
10(2, −1)−8−17
11(2, 0)2−19
12(2, 1)14−21
13(2, 2)28−23
14(1, 2)29−25
15(0, 2)30−27
16(−1, 2)31−29
17(−2, 2)32−31
18(−2, 1)16−33
19(−2, 0)−2−35
20(−2, −1)−22−37
21(−2, −2)−44−39
22(−1, −2)−45−41
23(0, −2)−46−43
24(1, −2)−47−45
25(2, −2)−48−47
26(3, −2)−49−49: hit

The charges wander because each is aimed at a different submarine. Not one of the 25 misses told the hunter anything, and the hunter did not need to be told.

An earlier version of the script had (3,−2) caught on turn 43. Turn 43 is real, but it belongs to (−3, −3).

Hunt it yourself

Pick a submarine and a hunter, and step through the turns. A shaded square is a submarine that cannot be there, because it would have been sunk already: everything the misses rule out between them. The spiral and the formula clear the whole box. The sweep does not.

The film's submarine (3, −2), and every submarine with |a|, |v| ≤ 6
HunterCatches (3, −2)Has sunk all 169 by
Walk the spiralturn 26turn 169
Cantor's formulaturn 2turn 313
Sweep the linenevernever: it only ever sinks 39 of them

Generalising

Acceleration. A submarine at a+vt+wt2 has three hidden numbers, and triples can be listed too, shell by shell round the origin. Proof three applies unchanged. The script lists the 343 triples with every entry from −3 to 3 and checks that each is sunk by its own place:

Accelerating submarines, hunted on the list of triples
SubmarinePlace on the listCaught on turnAt
t²339
1 − t + t²2424553
−2 + 3t − t²21610
3 − 2t²298298−177,605

The third was sunk on turn 1, by luck: turn 1's charge is on 0, and so is it.

More hidden numbers. Any fixed number of hidden whole numbers can be listed, so a submarine in the plane, with a start (a1,a2) and a velocity (u1,u2), is caught by listing quadruples. A polynomial path of any degree with whole coefficients can be listed as well, degree and coefficients together.

Irrational speeds. A submarine with speed 2 must still be on whole numbers, so say it is at ⌊t2⌋. That is not a straight line, since it steps by 1 on some turns and by 2 on others. But it is one rule, so a longer list catches it: list the submarines a+⌊tm⌋, for every whole a and every m≥0, by Cantor's formula, and ⌊t2⌋ has place 6. What escapes a list is not being irrational, but being on no list at all.

What changes if the puzzle changes

Big families. The argument needs a family of paths that can be listed, which is what a mathematician calls countable. That is enough, but it is not necessary. The paths that sit on 0 at turn 1 are far too many to list, and one charge on 0 at turn 1 sinks every one of them. What can never be caught is the family of every path: whatever positions dt a hunter drops on, the submarine at dt+1 on every turn is never hit.

Real starts and speeds. If a and v may be any real numbers, with the submarine at ⌊a+vt⌋, the family is too big to list and the argument says nothing. Whether some cleverer hunter catches all of them is a different question, and this page does not settle it.

A submarine that reacts. Everything here assumes the rule is fixed before the hunt starts. If the submarine may watch the charges and change course, it just moves away from wherever the next one is going.

The sweep, revisited. The sweep does sink some submarines, just not reliably. On an odd turn 2k+1 it drops on −k, and on an even turn 2k on k, so it hits (a,v) only if one of

k(2v+1)=−(a+v)k(1−2v)=a

has a whole-number solution k, and neither has more than one. Of the 361 submarines with |a|,|v|≤9 it ever sinks 65. The other 296 it never will, however long it runs. In the film the sweep plays against (−11,2), for which neither equation has a solution, so those misses would go on for ever.

The sweep against the 361 submarines with |a|, |v| ≤ 9, by speed
SpeedSubmarinesEver caught by the sweep
−2193
−1199
01919
1199
2195

Taking it further: how fast can a hunter be?

The spiral clears the box |a|,|v|≤r, all (2r+1)2 submarines in it, by turn (2r+1)2, one pair a turn. One charge can sink several submarines at once, since every pair on the line a+vt=d is under it. So is there a quicker hunter?

Not much quicker. A charge on d at turn t sinks the pairs with a=d−vt, and inside the box that needs |d−vt|≤r, which at most ⌊2r/t⌋+1 speeds can manage. So any hunter that has cleared the box by turn T has

∑t=1T(⌊2rt⌋+1)≥(2r+1)2

The extra ∑⌊2r/t⌋ is only about 2rlnT, which is small next to 4r2, so for a big box nothing beats the spiral by more than a sliver. At r=1000 the bound is 0.996 of the spiral's time:

Clearing the box |a|, |v| ≤ r: the spiral against the best any hunter could do
rAny hunter needs at leastThe spiralCantor's formula
16913
2172541
3354985
9303361685
303,4603,7217,321
10039,30340,40180,401
10003,988,4834,004,0018,004,001

For the smallest box, r=1, the script searches every sequence of drops: the best possible is 7 turns, against the bound's 6 and the spiral's 9. Cantor's formula is about twice as slow on a big box. To reach every pair with |a|,|v|≤r it has to finish every diagonal up to a~+v~=4r, a triangle of about 8r2 places, where the spiral needs a square of about 4r2.

Checking it

None of the above is left to the proofs, as far as finite checking can go. scripts/submarine.mjs reads the film's own hunt.json and rebuilds it from scratch: the spiral's first 120 pairs, the 26 turns of the hunt, the turn-43 pair, the sweep, the film's sweep submarine and the fan of witnesses. Any disagreement stops the build.

The sweep is dead. For every turn up to 39 and every position from −25 to 25, with the film's own sweep as the misses, the script counts the speeds from −400 to 400 that those misses rule out. It is never more than the number of misses, and no position is ever ruled out. It does the same against a hunter who had dropped on every position from −t to t on every earlier turn, up to turn 24, and against random misses with several charges a turn.

The film's sweep: what its misses rule out at each position from −25 to 25, by turn t
Turn tMissesMost speeds lost at a positionPositions ruled out
1000
2110
5430
10940
201960
393870
Random misses, m charges a turn: speeds lost at a position, against the bound m(t − 1)
Charges a turnCasesWorst share of the boundRuled out
125271%0
325258%0
1025246%0

Every submarine in a box. Both lists are run against every pair in the box. Each pair is checked to be under the charge on its own place, and to be sunk no later than that. Sunk early counts the pairs a charge meant for another pair caught first. The mean is the turn it is actually sunk, luck included.

Every submarine with |a|, |v| ≤ R, hunted two ways: all are sunk by their deadlines
ListRLast deadlineSunk earlyMean turn
Spiral936140163.4
Spiral1596175450.7
Formula968542188.1
Formula151,86183521.2

The rest. The spiral is checked for 4,000 steps to be one unbroken path with no repeats, and its place formula is checked against the walk. Cantor's formula is checked to be a one-to-one list on its first 200,000 places and on every pair with |a|,|v|≤50. The sweep's two equations are checked against the sweep itself for every pair with |a|,|v|≤20 over 4,000 turns, and (−11,2) survives 100,000 turns of it. The limit of ⌊2r/t⌋+1 submarines a charge is checked for every possible charge up to r=6 and t=60, and the table above uses it. The hunt lab runs the same functions this script imports, and the script checks the pasted copy against them, square by square.

What is not checked. A script can check every submarine in a box, but not every submarine. That all of them are caught is the proof, which is short enough to check by eye. What the script vouches for is that the hunt is built the way the proof says, and that every finite claim on this page is true.

Where this shows up

  • Countable sets. That the pairs of whole numbers can be put in one list, while the real numbers cannot, goes back to Cantor in the 1870s. Proof two is the standard way to show the first half.
  • Dovetailing. In computing, running infinitely many processes at once, by giving step j of process i the place the pairing formula gives (i,j), is called dovetailing. It is how one shows that the outputs of all programs can be listed, and it is proof two.
  • Searching the parameters. When the thing you want is fixed by a few unknown whole numbers, search the numbers rather than the thing. Levin's universal search, from 1973, applies the idea to programs themselves, running every program on an interleaved schedule of this kind.

Try it yourself

1. On the film's spiral, which turn sinks the submarine that starts at 0 and moves 1 a turn?

Turn 4, at 4. (0,1) is the fourth pair on the walk, after (0,0), (1,0) and (1,1), so turn 4's charge is at 0+1×4. None of the first three charges lands on it.

2. Show that the sweep 0,1,−1,2,−2,… never sinks the submarine that starts at −11 and moves 2 a turn.

On an odd turn 2k+1 the sweep is at −k and the submarine at −11+2(2k+1)=4k−9, which would need 5k=9. On an even turn 2k the sweep is at k and the submarine at 4k−11, which would need 3k=11. Neither has a whole-number solution. The script also runs the two for 100,000 turns.

3. With ten charges a turn, could a sweep of positions work?

No. Each charge rules out at most one speed for each position, so after t−1 turns a position has lost at most 10(t−1) of its infinitely many speeds, and it is still possible. Any finite number of charges a turn gives the same answer. In the script's random histories with ten charges a turn, no position ever lost more than 46% of that allowance, and none was ruled out.

4. A submarine moves in the plane, starting at an unknown whole-number point and moving by the same unknown whole-number step every turn. How do you hunt it?

List the four hidden numbers (a1,a2,u1,u2), shell by shell, and on turn t drop on (a1+u1t,a2+u2t) for the t-th quadruple. The 81 submarines with every entry from −1 to 1 come first, and each is sunk by turn 81.