Thinking through a logic circuit one gate at a time
What AND, OR, XOR and NAND actually do, how to read the wiring and the truth table, why fixing one row can break another, and the method that finds the right gate without guessing.

What the puzzle asks you to do
A lamp sits at the end of a short chain of sockets. Each socket takes one logic gate. The sockets are wired to the input switches or to earlier sockets, and the last socket drives the lamp. A truth table on the page lists every combination of the input switches and says what the lamp should do for each one.
Your job is to drop a gate into every socket so the lamp matches every row of the table at the same time. One row right is not enough. All of them must agree before the puzzle counts as solved.
The four gates and what they do
AND lights its output only when both of its wires are on. If either wire is off, the output stays off. It is the strictest gate, and it fires the least often.
OR lights when at least one wire is on. It only stays dark when both wires are off. OR is the loosest gate and fires the most.
XOR lights when exactly one wire is on. If both are on, or both are off, the output stays dark. It is the gate that separates the rows where the two inputs differ from the rows where they match.
NAND is AND turned upside down. It is dark only when both wires are on, and lights every other time. If you try AND and every row comes out backwards, NAND is the fix.
Reading the wiring
Above each gate is a label that names the two things feeding it. A and B are the input switches. On a three-input board you also see C. The labels g1, g2, g3 and so on refer to earlier sockets by their position in the chain.
No socket can feed itself. Each one may only draw on the switches or on a socket that comes before it, so the circuit flows in one direction from left to right and can never loop. That matters because it means you can always work forward: the first socket sees only the raw switches, so its output depends on nothing else.
The truth table, row by row
The table has one row for every possible combination of the input switches. Two switches give four rows. Three switches give eight. Each row shows the switch settings on the left, the wanted lamp state in the middle, and what the lamp actually does with the gates you have chosen.
Rows where the two columns match are marked green. Rows that disagree are marked red. The puzzle is solved when every row is green.
The table is the single most useful thing on the page. When you tap a gate and the colours change, the pattern of red and green tells you whether you moved closer or further away.
How to play
Tap a socket to cycle its gate through AND, OR, XOR and NAND. Each tap counts as one change. The table updates instantly, colouring every row green or red.
A dropdown lets you pick the board size. Small gives two input switches and two sockets. Medium raises both to three. Large keeps three switches but adds a fourth socket, which makes the chain longer and the reasoning harder.
The stats bar shows how many rows are currently right, the total number of rows, and your change count. When every row turns green the puzzle is done and your count is saved.
Start at the first socket
The first socket in the chain sees only the raw switches. No earlier gate sits between them. That means its output is entirely decided by which gate you put in it.
Work out the output of each gate for every switch setting. Compare each pattern against the wanted column. If no single gate matches the wanted column exactly, that is normal. The first socket is feeding into the next one, and the final answer comes from the end of the chain, not from one socket alone.
But settling the first socket narrows the problem. Once its output is fixed, the second socket has a known set of inputs rather than four unknowns. That forward pass is the backbone of every solve.
Using the red rows to identify the gate
Suppose two rows are red and two are green. Look at what the two inputs to the socket have in common on the red rows. If the red rows are exactly the ones where the two wires disagree, you need an XOR. If the red rows are the ones where both wires are on, AND is wrong and you need something else.
This pattern-matching shortcut is faster than cycling through all four gates. You are not guessing at random. You are reading the table and letting it tell you the answer.
The key insight is that AND, OR and NAND all agree when both inputs match. Only XOR gives a different answer on those rows. So XOR is the gate that fixes the hardest tables, and it is usually the one beginners overlook.
Why one answer and not several
With four gates and up to four sockets, there are at most 256 possible circuits. The generator builds all of them, evaluates each one against the table, and counts how many produce the right output for every row. The puzzle is only used when exactly one arrangement works.
The wiring is also checked. Every socket must feed something that reaches the lamp, and every input switch must be connected. A dangling socket could take any gate at all without changing the answer, which would give the puzzle multiple solutions. Those are thrown out.
Tables where the lamp is always on or always off are rejected too. They carry no information and would make the puzzle trivial.
Counting the ones in the wanted column
Before you touch a gate, look at how many ones and zeros sit in the wanted column. AND lights rarely. In a four-row table, AND produces a single one. OR lights often, giving three ones out of four. NAND is the mirror of AND, so it also gives three ones. XOR sits in the middle with two.
If the wanted column is mostly ones, an OR or NAND is more likely at the socket that feeds the lamp. If it is mostly zeros, AND deserves a look. This quick count does not solve the puzzle by itself, but it shrinks the guessing space before you start cycling.
Mistakes that waste changes
The most common mistake is fixing one row and forgetting the rest. You see a red row, cycle the nearest gate until that row turns green, and celebrate. But three other rows just flipped to red. The table judges all rows at once, and a gate that helps one row while hurting another is not progress.
Another trap is ignoring NAND. Beginners cycle through AND, OR and XOR and then move to the next socket. But NAND is the mirror image of AND, and sometimes it is the only gate that works. Skipping it means cycling all the way around again.
- Always check every row after a change, not just the one you were targeting.
- Count how many rows are on in the wanted column. If most are on, OR or NAND is more likely than AND.
- If AND produces the exact opposite of what you need, NAND is the one-tap fix.
- Work forward from the switches. Settle the first socket before touching the second.
- On a large board, the last socket depends on everything before it. Changing a socket near the start can ripple all the way to the lamp.
A short walkthrough on a small board
Two switches, A and B. Two sockets, g1 wired to A and B, g2 wired to g1 and A. The wanted column reads 0, 1, 0, 1. That means the lamp should be on only when A is on, regardless of B.
Socket g1 sees A and B. Try OR: the output is 0, 1, 1, 1. Try AND: the output is 0, 0, 0, 1. Try XOR: the output is 0, 1, 1, 0. None of these alone match, and they do not need to. Socket g2 combines g1 with A.
Set g1 to OR. Now g2 sees the OR output and A. The wanted lamp is 0, 1, 0, 1. That is exactly the value of A, so g2 must produce A from its two inputs. The AND of OR-output and A gives 0, 0, 0, 1. Not right. XOR gives 0, 0, 1, 1. Not right either. Try setting g1 to AND instead and g2 to OR. The chain now reads 0, 0, 0, 1 into OR with A, which gives 0, 1, 0, 1. Every row is green.
Everything stays on your device
The wiring, the gates and the truth table are all generated inside your browser. No puzzle is fetched from a server, no solution is uploaded, and no account is needed. You can disconnect from the internet after the page loads and keep playing. Every move and every best score lives in this browser on this device and nowhere else.
