Bite 3.5.8 · Modelling Challenges

Logical thermometers, beyond temperature

Modeling this puzzle using integer optimization

Image by Markus Winkler · Unsplash

The Thermometer Puzzle is an original logic puzzle where cold calculation meets spatial design. Here, capacity constraints and the physical continuity of fluids come into play.

The goal is to determine which cells of an $m \times n$ grid contain mercury. The grid is completely covered by thermometers of various shapes and lengths. Each thermometer occupies a sequence of adjacent cells (horizontally or vertically) and has a clearly identifiable base or “bulb”.

Formal description of the problem

Given an $m \times n$ grid of cells grouped into different thermometers, we must decide the fill level of each one while respecting the following physical and logical rules:

  1. Row and column requirements: The grid margins indicate exactly how many cells must be filled with mercury in each row and in each column.
  2. Continuous filling (Gravity/Thermometer physics): Thermometers are always filled from the bulb (start) towards the tail end. This implies a strict condition: if a cell contains mercury, all preceding cells in that same thermometer (closer to the bulb) must also be filled. Likewise, if a cell is empty, all subsequent cells in that thermometer must be empty.

Consider the following example of an $8 \times 8$ board:

Would you like to try solving it logically before checking its mathematical modeling?


The magic of this puzzle lies in crossing the information from marginal totals with the directional rigidity of the thermometers. How do we model this apparent “fluid physics” mathematically? By using the elegance of binary linear optimization.

Keep following the series

← Previous · 3.5.7Dominosa Modelling Challenges Next · 3.5.9 →Queens Dominating the Board

How to cite

Cite this post

Martín-Campo, F. Javier (2026). Logical thermometers, beyond temperature. https://www.fjmartincampo.com/blog/2026/thermometers/

As a BibTeX entry:

@misc{martín-campo2026logical-thermometers-beyond-temperature,
  title   = {Logical thermometers, beyond temperature},
  author  = {Martín-Campo, F. Javier},
  year    = {2026},
  month   = {jun},
  url     = {https://www.fjmartincampo.com/blog/2026/thermometers/}
}

This post is published under a CC BY-NC-SA 4.0 license.