engineering

An Advent of Operational Models

0:00 / 0:00

This December, we’re using Advent of Code to see where operational models help. We start with six containers in a dusty shed.

5 min read
Yurii Rashkovskii
Yurii Rashkovskii
Founder
Six metal parts bins on a wooden shelf beneath a work lamp in a shed at dusk.

Put six containers on a shelf and label them 8, 8, 2, 2, 4, 6. Two labels have twins. Two are on their own. Pick the three most common labels and multiply them. Then do the same with the three least common. You can work through both before the kettle boils. The interesting bit starts when you have to show someone how you picked the third container type.

That’s Dusty Shed, the first puzzle in Advent of Code 2026, in miniature. For this series, AI writes the solutions and we check them. It’s a familiar workflow for most Inferal users. They describe how their operation works, and AI writes the rules in Seer, Inferal’s formal language for operational models.

A traditional script lays out a sequence of steps. A Seer model describes how results depend on facts and on one another. Seer evaluates those rules deterministically. Run the same rules on the same observations and you’ll get the same tally. Add a container and you can follow the change all the way to the answer.

Open the Rule graph tab in either player below to see how the tally feeds the ranking and the ranking feeds the final product. As the puzzles get harder, we’ll see which ones are easier to understand this way.

Day 1. A shelf full of duplicates

Each line describes one container. If the same ID appears twice, you need to count both containers. A Seer set stores each distinct row once, so we give each observation a line number. Now the two containers labeled 8 have different rows and still count toward the same ID.

Our little shelf has two 2s, two 8s, one 4, and one 6. Our sample uses the lower ID to break ties. For Part 1 the ranking starts with 2 and 8, and 4 takes the last seat. The product is 64.

Dusty Shed, Part 1: three most frequent IDs
Part 1. Read the brass rows by rank to see where each factor comes from.

Part 2 puts the smallest counts first. 4 and 6 move to the front, then 2 beats 8 for third. The product is 48. Same six containers, different three factors.

Dusty Shed, Part 2: three least frequent IDs
Part 2. The counts stay put while the highlighted IDs change.

The part that reads like the puzzle

A short script can count the IDs, sort them, and print the answer. We wanted to keep the useful intermediate results around too. In Seer, the counts are rows in a relation called frequency. A ranked window takes those rows and publishes the three selected IDs with their positions.

rule rank_most_frequent_ids
keep [frequency(id: Id, occurrences: Count)]
window first 3 rows by (Count desc, Id asc) with rank Rank
maintain [top_three(Rank, Id)]

For Part 2, the rule becomes rank_least_frequent_ids and uses Count asc. Keep Id asc so ties work the same way. The chart and multiply_top_three_ids both read top_three, so the highlighted IDs are the ones that actually went into the answer. We checked the two saved demos against independent counts, then opened the downloaded copies offline to make sure the browser could run the same rules on its own.

Try one more thought experiment. Slide another 6 onto the shelf. Now it ties with 2 and 8 on count, and Part 1 becomes 2 × 6 × 8 = 96. The tally, the three ranks, and the product all follow from one extra observation. In a stateful Seer run, you can apply that change as input and have the derived rows update with it.

Where we’d reach for Seer again

For a one-off number, I’d happily use a few lines of Python. Give the shed a million rows and you still have the same job, just with more containers to count. The case for Seer gets stronger when more things depend on the same facts and those facts can change.

Suppose the shed starts receiving scans throughout the day. A chart shows the busiest IDs, a restock report uses the full counts, and a correction can relabel a container after both are open. In Seer, the correction goes into one observation relation. The counts update, the old ranks can be withdrawn, and each report reads the current rows it needs. You also have two places to look when the result surprises you: the counts, then the selection.

The tradeoff is that you have to think about the shape of your facts. Here, a line number is the difference between counting containers and counting distinct labels. A puzzle with an essentially sequential process may be clearer as a loop. We’ll look for both kinds as the calendar opens up.

When we’d bring in a solver

Three timber shelves in the shed. The top holds separate bins for an electric motor and coiled cable, the middle holds a bin of bolts, and the bottom is empty.

Day 1 gets its answer by counting and sorting. Now imagine we have to put three bins on shelves. The motor weighs six kilos and fits only on shelf 1. The bolts and cable weigh four kilos each. We want to use as few shelves as possible while staying within each shelf’s weight limit.

Seer also has a built-in constraint solver. The rules work out which shelves each bin could go on. A solve block describes what a complete placement has to satisfy and what to optimize. Here the solver uses those rules and constraints to find a placement that opens the fewest shelves.

relation bin(name String, weight Int) : set
relation shelf(number Int, capacity Int) : set
relation blocked(name String, shelf Int) : set
relation eligible(name String, shelf Int) : set
relation available(shelf Int) : set
relation placed(name String, shelf Int) : set
relation opened(shelf Int) : set

fact bin("motor", 6)
fact bin("bolts", 4)
fact bin("cable", 4)
fact shelf(1, 10)
fact shelf(2, 8)
fact shelf(3, 8)
fact blocked("motor", 2)
fact blocked("motor", 3)

// Rule out forbidden pairs and bins that are too heavy for a shelf on their own.
rule find_eligible_placements
keep [bin(name: B, weight: Weight), shelf(number: S, capacity: Limit)]
absent [blocked(name: B, shelf: S)]
where Weight <= Limit
maintain [eligible(B, S)]

// Only shelves present in the input can be opened.
rule list_available_shelves
keep [shelf(number: S, capacity: _Limit)]
maintain [available(S)]

solve pack {
  constraint placement: placed subset of eligible;
  constraint existing_shelf: opened subset of available;

  // Give every bin exactly one destination.
  constraint once(B) for [bin(name: B, weight: _Weight)]
    require size { S | placed(name: B, shelf: S) } = 1;

  // With no opened row for S, the count is zero and the shelf holds no weight.
  constraint capacity(S) for [shelf(number: S, capacity: Limit)]
    require sum { B -> Weight | bin(name: B, weight: Weight), placed(name: B, shelf: S) }
      <= Limit * size { S | opened(shelf: S) };

  minimize shelf_count: size(opened);
}

The solver found an optimum of two shelves. One solution puts the motor and cable on shelf 1 (10 kg) and the bolts on shelf 2 (4 kg). The bins weigh 14 kg in all, so they cannot fit on a single shelf with a limit of at most 10 kg. Seer returns the placements as rows a report can read directly. A later puzzle with choices like these would give us a reason to use the solver in the series.

To be continued. Next time, a different puzzle gets the shelf space.


Share