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.
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.
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:
| Grid | Thermometers (avg) | Possible fillings | If cells were independent |
|---|---|---|---|
| 4×4 straight | 6 | about 2,500 | about 66,000 |
| 6×6 straight | 13 | about 107 | about 1011 |
| 8×8 straight | 22 | about 1013 | about 1019 |
| 10×10 straight | 32 | about 1019 | about 1030 |
| 12×12 straight | 45 | about 1027 | about 1043 |
| 15×15 straight | 72 | about 1043 | about 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?
Why does a puzzle need a unique solution?
See the math in action
Every deduction you make is a bound on a fill level.