I spend way too much time on Jane Street’s monthly puzzles. February 2026 almost broke me.

It’s called Subtiles 2. The gist: you get a 13x13 grid, some cells have algebraic expressions instead of numbers, and you need to tile the whole thing with shapes that nest inside each other, like Russian dolls made of grid squares. I stared at the rules for twenty minutes before I even understood what “containment” meant.

I ended up writing a C++ solver for this, because doing it by hand wasn’t going to happen. This post walks through how I got there.

The rules

There are five, and they sound innocent.

  1. Fill cells with positive integers. The grid needs exactly one 1, two 2s, three 3s, … up to N copies of N. (Turns out N=16 for this puzzle. That’s 1+2+3+…+16 = 136 cells to fill on a 13x13 = 169 grid. So 33 cells stay empty.)

  2. All cells with the same number K must form a connected blob. You can walk between any two K-cells going only up/down/left/right through other K-cells. The fancy word for this is a K-omino.

  3. This is the killer. Each K-omino must contain the (K-1)-omino’s shape. You’re allowed to rotate and flip, but the geometry has to nest. The 6-omino is the 5-omino with one cell glued on, the 5-omino is the 4-omino with one cell glued on, and so on all the way down.

  4. Some cells come pre-labeled with expressions using variables a, b, c. You figure out those variables first.

  5. Sum each row. The answer is the min row sum times the max row sum.

What “contain” means in practice

I got confused here, so let me be specific. Say you’ve placed the 3s and they form an L-shape. Now you need to place four 4s. Those four cells must form a shape where, if you remove one cell, you’re left with something that can be rotated/flipped to match the 3s’ L-shape.

Each level is the previous level plus one cell, growing outward one square at a time:

Step 1:  X           just a dot

Step 2:  X X         grew right

Step 3:  X X         grew down
         X

Step 4:  X X         grew down again
         X
         X

At every step, the old shape is still in there somewhere.

First problem: what are a, b, c?

Before touching the grid, you’ve gotta crack the variables. The puzzle image has cells with stuff like c^b, b^2, (2^b + 1)/(ac), and 34 other expressions. Every one of them needs to evaluate to a positive integer between 1 and 17 (1+2+…+17 = 153 still fits in 169 cells, and 18 would not).

That’s a pretty tight constraint, so I brute-forced it: loop over small values of a, b, c (negatives and simple fractions included), evaluate all the expressions, and check that they all come out to integers in range. Not many combos survive. The one that works is a = 1/4, b = -3, c = 1/2.

Once you’ve got the values, those expressions turn into hard clues. My solver stores the resolved numbers directly:

// {row, col, value} - the resolved clue cells
const vector<tuple<int, int, int>> clue_list = {
    {0,4,15}, {1,7,11},
    {2,1,15}, {2,3,5}, {2,6,15}, {2,8,11}, {2,10,11},
    {3,4,15}, {3,7,8}, {3,9,12}, {3,11,12},
    {4,1,16}, {4,5,8}, {4,10,6},
    {5,3,16}, {5,12,6},
    {6,2,16}, {6,4,3}, {6,6,16}, {6,8,1}, {6,10,12},
    {7,0,13}, {7,9,4},
    {8,2,7}, {8,7,12}, {8,11,10},
    {9,1,2}, {9,3,13}, {9,5,16}, {9,8,14},
    {10,2,13}, {10,4,14}, {10,6,14}, {10,9,14}, {10,11,10},
    {11,5,9}, {12,8,9},
};

That’s 37 clue cells locked in. The rest is up to the solver.

Building every possible shape

You know Tetris pieces? Those are the 5 tetrominoes (4-cell shapes). There are 12 pentominoes (5 cells), 35 hexominoes (6 cells), and the numbers keep growing. By the time you hit 16-cell shapes, there are millions.

We don’t need all of them, though. We only need shapes that could appear in the solution, meaning ones that can be placed on the grid to cover all the clue cells for their value.

The solver grows shapes from size 1 upward. Take every valid (K-1)-omino. For each one, try sticking a new cell on every exposed edge. Normalize the result (shift it so the top-left corner is at (0,0), sort the cells) so we don’t count the same shape twice.

for (auto& parent : valid_shapes[k - 1]) {
    // find all empty neighbors of this shape
    set<Cell> neighbors;
    for (auto [r, c] : parent)
        for (auto [dr, dc] : vector<Cell>{{1,0},{-1,0},{0,1},{0,-1}}) {
            Cell n = {r + dr, c + dc};
            if (!parent_cells.count(n))
                neighbors.insert(n);
        }

    // try adding each neighbor
    for (auto neighbor : neighbors) {
        auto child = parent;
        child.push_back(neighbor);
        Shape normalized = normalize_shape(child);
        // keep it only if it could cover the required clue cells
        if (can_cover_clues(normalized, k))
            valid_shapes[k].insert(normalized);
    }
}

That can_cover_clues check does most of the work. Value 15 has four clue cells scattered across the grid. Any 15-omino shape that can’t reach all four positions (after trying all 8 rotations/reflections) gets tossed immediately. This kills most candidates early.

Pruning the dead branches

After growing shapes all the way to size 16, I run a backward pass. If a shape at size K has no valid child at size K+1, it’s a dead end, so I remove it. Then I check K-1 again, because removing a shape might orphan its parents, and repeat down to 1.

for (int k = MAX_VALUE; k > 1; k--) {
    set<Shape> surviving_parents;
    for (auto& [child, its_parents] : parent_shapes[k])
        if (valid_shapes[k].count(child))
            for (auto& p : its_parents)
                surviving_parents.insert(p);
    valid_shapes[k - 1] = surviving_parents;
}

Think of it like trimming a tree. If a branch doesn’t reach the canopy, cut it at the trunk.

Placing shapes on the grid

A “shape” is abstract. An L-piece is an L-piece regardless of where it sits. A placement is that same L-piece nailed down to specific grid coordinates.

For every value K, I go through every surviving K-omino shape, every rotation and reflection, and every valid position on the 13x13 grid. Does it cover the clue cells? Does it avoid cells claimed by other values? Does it stay in bounds?

The ones that pass all three checks get stored. I printed the counts while debugging and… yeah. Value 10 has over 10,000 valid placements. Value 12, pinned by four clue cells, has 48. The solver ended up relying on that asymmetry.

Start from the middle

The search order is what I’m most proud of.

My first attempt placed values 1, 2, 3, 4, … in order. It ran for 40 minutes before I killed it. The problem is obvious in hindsight. The small values are cheap to place (the 1 is a clue cell, the 2 has 8 placements, the 3 has 48), but they tell you almost nothing about the big shapes. By the time the search reaches 7 through 10 it is branching over thousands of placements for each value, and the values that would rule most of them out come last.

So I flipped it and started with the most constrained of the big values. For my puzzle, that was K=12, which had only 48 placements after all the pruning, against 1,160 for 11 and 736 for 13. Place the 12-omino first, then expand outward in both directions:

12 → 11 → 13 → 10 → 14 → 9 → 15 → 8 → 16 → 7 → 6 → 5 → 4 → 3 → 2 → 1

When you place 11, you already know 12’s shape, so 11 must be a valid parent of 12 (remove one cell and you get 11’s shape). When you place 13, it must be a valid child of 12 (12’s shape plus one cell). Either way, the containment constraint slashes the candidate list.

const SolveStep solve_order[] = {
    {12, 0,  false},                      // seed: try all 12-placements
    {11, 12, false}, {13, 12, true},      // neighbors of 12
    {10, 11, false}, {14, 13, true},      // neighbors of 11 and 13
    { 9, 10, false}, {15, 14, true},
    { 8,  9, false}, {16, 15, true},
    { 7,  8, false},                      // rest goes downward
    { 6,  7, false}, { 5,  6, false},
    { 4,  5, false}, { 3,  4, false},
    { 2,  3, false}, { 1,  2, false},
};

I precompute compatibility tables so these lookups are instant during backtracking. Given a shape at size K, I already know which placements at K-1 and K+1 are compatible.

The backtracker

After all that prep work, the solver itself is simple. It’s standard recursive backtracking:

bool solve(int step) {
    if (step == 16) return true;  // done!

    int k = solve_order[step].k;
    const vector<int>* candidates = /* from compatibility table */;

    for (int idx : *candidates) {
        auto& p = all_placements[k][idx];

        // skip if any cell is already taken
        bool ok = true;
        for (auto [r, c] : p.cells)
            if (grid[r][c] != 0) { ok = false; break; }
        if (!ok) continue;

        // place
        for (auto [r, c] : p.cells) grid[r][c] = k;
        chosen_shape[k] = p.shape;

        if (solve(step + 1)) return true;

        // undo
        for (auto [r, c] : p.cells) grid[r][c] = 0;
    }
    return false;
}

Try a placement and recurse. If it works, we’re done. If not, undo and try the next one. All the cleverness is in the ordering and pruning that happened before this function ever runs.

Getting the answer

Once the grid’s full, sum each row and multiply the smallest and largest sums.

int min_sum = 9999, max_sum = 0;
for (int row = 0; row < GRID_SIZE; row++) {
    int s = 0;
    for (int col = 0; col < GRID_SIZE; col++)
        s += grid[row][col];
    min_sum = min(min_sum, s);
    max_sum = max(max_sum, s);
}
cout << "answer: " << min_sum * max_sum << endl;

What I learned

Three things made this problem solvable.

Grow the shapes instead of enumerating them. Generating all 16-ominoes from scratch would be insane. Growing them from smaller shapes, and killing dead branches as you go, keeps the numbers manageable.

Precompute everything you can. The compatibility tables (which shapes at K are children/parents of which shapes at K-1) get built once, so during backtracking, finding candidates is a map lookup.

Start where the constraints are tightest. This one I learned the hard way. My first solver choked because it started from K=1 and drowned in possibilities. Starting from K=12 and expanding outward means every step has a small candidate set, and that took the solver from “runs forever” to about half a minute on an Apple M4 Pro. Nearly all of that is shape generation. The backtracking itself finishes in under a millisecond.

Build it yourself

Full source: GitHub

g++ -O2 -std=c++17 -o subtiles feb-2026.cpp
./subtiles

It prints the filled grid and the answer. Runtime depends on your machine but it’s not bad once the pruning does its job.

References