Guide · Deep dive

The math of thermometer puzzles

You don't need any math to solve a thermometer puzzle, but a little of it explains why the techniques work, why the puzzles are fair, and why they are so much more structured than they look.

Updated · 4 min read

Part of the complete guide to thermometer puzzles · guide 4 of 7

Each thermometer is a single number

Because mercury fills from the bulb without gaps, a thermometer's whole state is described by one number, its fill level: how many cells, counted from the bulb, contain mercury. A thermometer of length L can be at level 0, 1, 2, … , L. That is L + 1 states, not the 2L you would get if each cell could be filled independently.

Level 0
Level 1
Level 2
Level 3
Level 4

How many arrangements does a grid have?

Multiply the number of states of every thermometer: a grid with thermometers of lengths L1, L2, … has (L1+1)(L2+1)… possible fillings before any clue is applied. We measured this on puzzles from our generator:

GridThermometers (avg)Possible fillingsIf cells were independent
4×4 straight6about 2,500about 66,000
6×6 straight13about 107about 1011
8×8 straight22about 1013about 1019
10×10 straight32about 1019about 1030
12×12 straight45about 1027about 1043
15×15 straight72about 1043about 1068

Averages over 8 generated puzzles per size.

The thermometers remove the vast majority of possibilities before you read a single clue. The clues then cut the remaining space down to exactly one arrangement.

The checksum: rows and columns agree

Every mercury cell is in exactly one row and exactly one column. So the row clues and the column clues each add up to the total number of mercury cells:

sum of row clues = sum of column clues = total mercury

This gives you a free check while solving, and a useful extra fact on large puzzles. Battleships has the same property, since its clues are also plain counts (see how the two compare). In our puzzles, mercury fills on average about 52% of a 10×10 grid.

Why the squeeze works: contributions only grow

Fix a line and a thermometer. As the fill level rises, the number of the thermometer's cells in that line can only stay the same or go up. It never goes down. In math terms, the contribution is a monotone function of the level. That is why a lower bound on the contribution becomes a lower bound on the level (fill from the bulb), and an upper bound becomes an upper bound (air toward the tip).

The squeeze and ceiling rule is then just interval arithmetic. If the rest of the line can supply between a and b cells, this thermometer must supply between c − b and c − a. Repeating this over every line until nothing changes is called bounds propagation, and it is exactly how our solver reasons.

When propagation isn't enough

Bounds propagation can stall with cells still open. The next step up is a one-step lookahead: suppose a thermometer is at its lowest (or highest) remaining level, propagate, and if that leads to an impossible line, rule the level out. This is the formal version of the solver's proof by contradiction. Every puzzle on this site is solvable using propagation plus this one-step lookahead. That guarantee is how we know no puzzle needs guessing. The details are in how our puzzles are generated.

Curved thermometers

Everything above holds for curved thermometers too. The only difference is that a curved tube's contribution to a line can grow in several separate jumps as it fills, because it may visit the line more than once. Curved grids also use fewer, longer thermometers (see sizes and variants): a 10×10 curved puzzle averaged 25 thermometers in our sample, versus 32 for straight ones.

Questions

Is solving thermometer puzzles computationally hard?
For the puzzles on this site, no: each one is generated so that bound reasoning (plus one step of lookahead) solves it completely. For arbitrary, badly designed grids, deciding whether a solution exists can require search, as with many grid puzzles.
Why does a puzzle need a unique solution?
If two different fillings both satisfied every clue, some cells could only be decided by guessing. A unique solution means every cell is forced by the clues, which is what makes the puzzle a puzzle of logic.

See the math in action

Every deduction you make is a bound on a fill level.

Play now →