The challenge
A NYT Pips puzzle is an irregular board of
cells grouped into coloured regions, each carrying a
constraint (a target sum, <N/>N,
“all equal” =, or
“all different” ≠). You must tile
every cell with a given multiset of dominoes so all constraints
hold. Two distinct problems: read the puzzle out of a
screenshot, and solve the
constraint problem. The parser turned out to be the harder
half. No machine learning and no network calls are used —
just classical computer vision.
Part 1 · Parsing the screenshot
Finding the cell grid
Problem: cells sit on a square lattice, but the pixel size of a cell differs between screenshots, and the board is an arbitrary polyomino, not a full rectangle.
Solution: the cell pitch is recovered from the periodic dip in brightness at the thin gaps between cells — an autocorrelation of that signal gives the period regardless of image scale. The lattice phase is then locked by sliding the grid and maximising how much solid cell-tile it covers, which works on any polyomino shape.
Cell vs. hole vs. background
Problem: a lattice slot may be a coloured region cell, a neutral “free” cell, an empty hole, or just the beige board frame. The free-cell beige and the frame beige differ by only ~14 in RGB, so a colour threshold was hopelessly fragile (it kept dropping free cells or inventing phantom ones).
Solution: stop using a background colour at all. A real cell is a large, uniform tile that fills its slot; a non-cell is white, or a thin strip of frame. So a slot is a cell iff a single dominant colour covers most of its area — a structural test that treats free and region cells identically and needs no fragile colour reference.
Disconnected boards (the hard puzzles)
Problem: hard puzzles are several separate board pieces scattered across the canvas, and the pieces are not aligned to one shared lattice — a single global grid missed most cells.
Solution: split the board into connected components and fit a lattice phase to each piece independently (the pitch is global, the phase is per-piece). Slot sampling is restricted to the piece being processed so a tight gap between two pieces can’t bleed one into the other. Each piece gets its own coordinate band so dominoes can never wrongly bridge a gap.
A subtle case: two pieces sometimes share a single rounded container drawn around both, with only a thin beige rim joining them — visually disconnected but pixel-connected. Eroding the board mask by ~12 px before labelling strips that thin rim (and the thin inter-cell gaps), so cluster IDs always come from a cell-bearing core. A cell tile is ~80 px on a side and easily survives the erosion.
Phone screenshots wrap the puzzle in app chrome
Problem: a phone screenshot is not just the puzzle — it’s a status bar, a browser header, the puzzle, a URL bar, app icons, etc., all stacked vertically. Tile-like UI elements (a Photos thumbnail strip, a URL pill) look superficially like dominoes; at the smaller mobile rendering scale a constraint tag can also become pixel-connected to its region’s dashed border, gluing several tags into one super-blob.
Solution: a one-shot puzzle locator runs first: it finds the warm-beige board container, then searches below it for a band of grey-scale tile components with the right ~2:1 domino aspect ratio, taking just the first band so app toolbars and thumbnails below the tray are left out. The image is cropped to that bounding box before the rest of the pipeline runs. When a saturated tag-detection blob exceeds a single tag’s area, it’s split via closing-then-erosion so each tag is recovered as its own seed, dilated back inside its own bbox so it can’t bleed into a merged neighbour. All remaining pixel thresholds (tag area, pip area, erosion radius, tile area) scale with the detected cell pitch, so the same code handles desktop pitches around 100 px and phone pitches that can drop below 60 px.
The same approach also forces the pitch-detection autocorrelation to prefer the fundamental period rather than a harmonic: the smallest lag whose autocorrelation is within 80% of the peak wins, so the parser doesn’t accidentally lock onto 2× the true pitch on puzzles where every other row happens to look similar.
Which cells form a region
Problem: clustering every cell colour globally merged genuinely separate regions that happened to share a hue (e.g. three different purple regions on one board).
Solution: a region is a connected component of equal-colour cells on the lattice. Same-coloured regions that are spatially apart stay distinct, which is exactly the game’s own rule.
Matching a constraint tag to its region
Problem: the little constraint markers are very saturated, while a region’s fill is a pale, desaturated tint — matching by raw colour failed, and several regions can share a tag colour. Nearest-cell matching swapped tags between neighbouring regions.
Solution: a region’s fill is its tag colour alpha-blended over beige, so the fill lies on the line segment between “beige” and “tag colour”. Tags are assigned to regions by an optimal (Hungarian) assignment on a cost that combines that colour-blend residual with spatial proximity: colour separates differently-hued neighbours, proximity separates regions that share a colour.
Reading the constraint text
Problem: the white glyph (a number, or
=/≠/</>)
is punched out of the solid tag, and small built-in OCR was
unreliable on it. The = symbol’s bars even reach
the tag edge, defeating naive flood-fill isolation.
Solution: recover the solid tag shape by
morphologically closing its colour mask (this re-seals the punched
text), and the glyph is then the bright pixels inside it. Split
that into characters by column gaps and classify each against a
small template library built once from real screenshots
(tools/build_templates.py). New glyphs —
>, the digit 0 from a
“>0” tag, multi-digit numbers like
11/14 — were added by labelling
them from new screenshots as they appeared.
Part 2 · Solving with an energy model
Problem: a brute-force tiling search is astronomically large, yet the answer must be exact — a “nearly right” board is wrong.
Solution: every region constraint contributes an
energy that is zero exactly when satisfied and grows with
the distance to satisfaction (see Constraint.violation).
A valid solution is an assignment of total energy 0. The solver
walks domino tilings depth-first, but for each region it keeps an
admissible lower bound on the energy still reachable given
the cells already filled (a partly-filled sum region can only land
in a known window of totals; an “all-equal” /
“all-different” region can only get worse). The branch
is pruned the instant any region can no longer reach 0. That
makes the search both exact and fast —
milliseconds even for the 28-cell hard board.
Because a found solution is only as trustworthy as the parse,
verify_solution independently re-checks the result
from scratch: every cell covered exactly once, each pair of cells
orthogonally adjacent, the domino multiset used exactly, and every
constraint satisfied at energy 0. Nothing is reported as
“solved” unless it passes that.
What “backtracking with admissible pruning” actually does
The solver is doing a depth-first traversal of a search tree. The root is an empty board; each node is a partial board state; each edge is “try this domino in this orientation, with these two cells”; a leaf is either a fully-tiled board (a candidate solution) or a dead end. Naively this tree is astronomical — for a 28-cell hard puzzle the unrestricted branching factor is in the dozens at every step, so the leaves number in the trillions.
What keeps it tractable is the per-region energy bound: every time a domino is placed, each touched region’s lower bound on its eventual energy is recomputed; if that bound is already above zero, the whole subtree below this node cannot reach energy 0 and we don’t explore it. For the easy puzzle pruning is so aggressive that no backtracking happens at all — the path is essentially straight. For the hard puzzles it’s the difference between “a few milliseconds” and “will not finish in the age of the universe.” The path the solver actually commits to is exactly the sequence of placements you see when you press Play on the solver view.
Part 3 · Running it in a browser
Problem: the parser/solver are Python (NumPy/SciPy/Pillow), but GitHub Pages only serves static files — no server to run Python on.
Solution: Pyodide runs CPython compiled to
WebAssembly in the browser. The page loads NumPy, SciPy and Pillow,
writes the unmodified pips package into the
virtual filesystem, and calls it directly — so results are
byte-identical to the command line. One sharp edge: GitHub Pages
runs Jekyll, which silently drops files beginning with
_ — including the glyph-template file. A
.nojekyll marker disables that.
The solution is also drawn graphically as an SVG: region-tinted cells, with each domino as a rounded tile — blue and wide for horizontal, orange and tall for vertical — so the placement and orientation are obvious at a glance.
Part 4 · When the parser isn’t sure
Why a review step is needed
Problem: the classical-CV pipeline is right almost
all the time, but at small renderings (a phone screenshot of a
screenshot, say) a tag glyph can occasionally be mis-classified
— the dashed boundaries are thicker relative to the
character strokes, one bar of an = bleeds into the
tag edge, and the runner-up template wins by a hair. Solving
against a wrong constraint silently gives the wrong answer, with
no signal to the user that anything is off.
Solution: the parser already carries soft signals at every stage; it just wasn’t surfacing them. The Help-Me mode keeps every per-item confidence score and, when any one of them falls below a threshold, the app pauses before solving and shows a Review panel where every parsed value — constraints, dominoes, even the cell-to-region assignments — is editable. The user confirms or corrects, hits Solve, and the corrected puzzle is solved by the same energy-model solver, bypassing the parser so the fixes always stick.
What “low confidence” means here
Each item gets its own kind of confidence signal — whatever the relevant stage of the pipeline already computes:
| Item | Signal | What it’s telling us |
|---|---|---|
| Region (constraint tag) | best template match score, and the margin to the runner-up template | how cleanly the glyph matched one character; a close runner-up means “could equally be that” |
| Region (matching) | Hungarian assignment cost (colour-blend residual + spatial gap) | how well this tag actually fits to its region by colour and proximity; a high cost suggests we ended up with the tag for the wrong region |
| Domino | count of pip-blob candidates whose pixel area sits between half and one-and-a-half times the threshold | any borderline blob means the parsed count could be off by one in either direction |
| Cell | slot coverage: fraction of the lattice slot occupied by a single uniform tile colour | coverage just above the existence threshold (0.60) is a cell only barely; might be a phantom slot near a board edge |
Why these thresholds
The thresholds were not picked theoretically — they came from looking at the empirical distribution of each signal across all the puzzles in the test set, and choosing the gap between “every correctly-parsed item” and “the few known mis-reads”:
| Signal | Threshold | Observed range (correct) | Observed (mis-read) |
|---|---|---|---|
| glyph score | < 0.85 |
0.92 – 1.00 | 0.732, 0.696 |
| glyph margin to runner-up | < 0.06 |
0.09 – 0.36 | 0.051, 0.015 |
| tag–region cost | > 32 |
typically 7 – 28 | (no observed mis-match yet; bound set well above the highest correct value) |
| borderline pip blobs | ≥ 1 |
0 on every parsed domino in the test set | any non-zero count means the count could be off |
| cell coverage | < 0.70 |
0.85 – 1.00 on real cells | just above the 0.60 existence cut-off is the danger zone |
So each threshold sits in the empty band between
“every correctly-parsed item” and any actual mis-read
we’ve seen — nothing correct is ever flagged, and the
two known mis-classified tags on the mobile screenshots
(= read as sum=1; 1 read as
≠) are flagged loudly. If a future puzzle adds a
new mis-read we’ll know exactly where in the table the new
data point lands, and whether the bands need re-tuning.
What gets edited, and what re-solves
The review panel makes every parsed item editable, not
just the flagged ones — the parser is occasionally
confidently wrong, and the review step is the only place to fix
that. Constraints get a kind dropdown plus a target field;
dominoes have two pip inputs; each board cell is a coloured
button, click cycles it through regions and right-click removes
it from the board entirely. Pressing Solve hands the (possibly
edited) structure to a separate
webapi.solve_structured entry-point that rebuilds
the puzzle from JSON and re-solves — the parser isn’t
involved at all, so any correction the user makes is the final
word.
A step-by-step walkthrough
Below is the easy puzzle taken through every stage of the pipeline. Drag the slider (or use the buttons) to step through. The first six steps are overlays on the original screenshot; the last few are the energy-model solver placing one domino at a time.
Where it stands
| Puzzle | Cells | Dominoes | Regions | Result |
|---|---|---|---|---|
| Easy | 8 | 4 | 4 | verified energy 0 |
| Medium | 14 | 7 | 7 | verified energy 0 |
| Hard (7 pieces) | 28 | 14 | 19 | verified energy 0 |
| Hard · Day 2 | 26 | 13 | 11 | verified energy 0 |
| Hard · Day 3 | 30 | 15 | 12 | verified energy 0 |
| Mobile screenshots (3) | 10/14/30 | 5/7/15 | 6/8/12 | verified energy 0 |
Each is parsed exactly — board shape, every constraint, every domino — and solved with an independently verified zero-energy solution; 12 end-to-end tests guard against regressions. Solving is a few milliseconds; parsing a screenshot takes a couple of seconds (most of it Pyodide’s one-time runtime download).