Charlie KrugThe Build Log

← All posts

Par is a shortest path through the space of boolean functions

Circuitle is a daily puzzle: match a truth table in the fewest logic gates. The par you're chasing isn't a hand-tuned guess, it's a shortest path found by searching every boolean function.

You wire up seven gates, every row of the truth table finally flips green, and you feel like you've built something clever. Then the result card says par is three. Somewhere there is a circuit that does the same job with three gates, and the puzzle is certain it exists even though it never shows you what it is.

What it is

Circuitle is a daily logic-gate puzzle. Each day you get one truth table, and your job is to build a circuit out of AND, OR, NOT, XOR, NAND, NOR, and XNOR gates that reproduces it. The only score is how many gates it took, golf-style, fewer is better. The target function is seeded from the UTC date, so everyone is solving the exact same board, and the share string (Circuitle 2026-07-06, then something like 3 gates (+2)) lets you compare counts without spoiling anyone's circuit.

The daily-puzzle genre is enormous and almost none of it asks you to reason about a computer science fundamental. Circuit minimization does. It has real depth (De Morgan's laws, gate-sharing, spending a NOT to turn an XOR into a free XNOR) and it collapses to a single number you can push down, which is exactly the shape a good golf puzzle wants.

The player never sees a solver

One deliberate decision: Circuitle simulates, it does not solve. When you drop or rewire a gate, it evaluates your circuit against every row of the target within a frame and marks each row pass or fail. That's the whole feedback loop. It will happily tell you that your circuit is wrong, or that it's correct and used six gates, but it will never hand you a better circuit. The reasoning stays yours.

Which raises the obvious question: if the game refuses to compute a solution, how does it know par is three?

Par is a graph search

It computes the floor without ever committing to a particular circuit. Here is the trick worth stealing. Forget circuits for a moment and think about functions. A boolean function on three inputs is completely described by its output column: eight rows, so eight bits, so one number between 0 and 255. On four inputs it's sixteen bits, one number up to 65,535. There are only that many distinct functions, full stop.

So par.ts treats each function as a node in a graph. The starting nodes are the input variables themselves (A, B, and C are functions you already have, for free). From any functions you can already build, applying a gate gives you a new function at a cost of one more gate: NOT flips a column you have, and the two-input gates combine any pair of columns. That's a weighted graph where distance is gate count, and finding par is just a shortest-path search (Dijkstra-flavored, breadth-first over gate count) from the inputs out to the day's target column. The distance when you arrive is the provably minimal number of gates. Not an estimate, not a designer's best attempt, the actual minimum.

Why it stays tractable

The reason this doesn't explode is that functions collapse. Thousands of different circuits produce the same sixteen-bit output column, and the search only ever keeps the cheapest way to reach each column, then stops expanding it. The state space is bounded by the number of functions (a few hundred for three inputs, 65,536 for four), not by the far larger number of possible circuits, so the whole thing terminates quickly and gets precomputed alongside the puzzle. That's also why par is honest enough to put a +2 next to your name: the game genuinely searched the space you're golfing in and found the bottom of it.

There's a real limitation hiding in that bound, and it's a fun one. This approach only stays cheap because four-input functions top out at 65,536 columns. Push to five or six inputs and the number of functions squares and squares again, and the tidy shortest-path search stops being tidy. The puzzle lives at three and four inputs partly because that's the largest board where I can promise par is truly minimal.

Try it

Open today's puzzle, read the Target table on the right, and drag gates from the dock onto the board. Click an input pin, then a gate input, to wire them; the table re-evaluates live after every change. Turn every row green to win, then do the harder thing: delete a gate and try to get back to all-green with one fewer. That second loop, re-solving smaller, is the actual game, and par is there to tell you exactly how much further down it can go.

Circuitle is live. Free, in your browser, no signup.

This post is part of the build log: every app my automated factory ships gets written up here, honestly. Browse everything at apps.charliekrug.com. Comments are open below.

Comments

Loading comments…