Sorter

Build a machine that puts things in order, then watch it run. The catch is that it has to work on any load it is handed, not just the one in front of you, so a rule that fits the sample and nothing else will not pass.

How to play

Each station clamps across two chutes and compares whatever arrives on them, sending the smaller of the pair up and the larger down.

  1. Watch the sample The load on screen shows what the machine does now. Try another load to see whether it was luck.
  2. Change a station Tap it to cycle which two chutes it joins. Order matters — the stations act one after another.
  3. Read the score Loads sorted counts how many of the test cases the machine currently handles. It must reach all of them.
Full instructions

In depth

Building a machine that sorts without seeing the load

What a comparator station does, why fixing one sample can ruin another, how the zero-one principle makes checking possible, and the bubble-sort pattern that solves most boards on the first try.

Screenshot: How to play Sorter
How to play Sorter as it appears when the page opens.

The puzzle in plain terms

Parcels drop down a set of chutes, one parcel per chute. Along the way they pass through stations. Each station joins two chutes with a comparator: it looks at the two parcels on those chutes and swaps them if they are in the wrong order, so the smaller one always ends up on the upper chute. The stations act in sequence, first to last, and each one does the same comparison every time regardless of what the parcels are.

Your job is to set the chute pair for each station so that the machine sorts every possible load, not just the sample you can see on screen. Tap a station to cycle which two chutes it joins. When the score reads all loads sorted, you win.

Controls and what the board shows

The top of the board shows a sample load: the parcels in their starting order on the left and the result after passing through the machine on the right. Below that sit the stations, numbered from first to last. Each station shows which two chutes it currently joins, written as a pair of numbers.

Tap any station to cycle its pair to the next combination. The sample result updates instantly. The Try another load button shuffles a new set of parcels through the same machine, so you can check whether a change that helped one arrangement breaks another. The stats row shows how many loads the machine currently sorts out of the total, and how many changes you have made.

The three machine sizes

The Machine dropdown offers Small, Medium, and Large. A Small machine has three chutes and three stations. With three chutes there are only six possible orders, so three stations is enough to sort them all. Medium has four chutes and five stations. Large has five chutes and nine stations.

As the number of chutes grows, the number of possible load orders grows as a factorial: six for three chutes, twenty-four for four, one hundred and twenty for five. The station counts given are exactly the minimum needed for a correct sorting network at each size, so no stations are wasted and none are spare.

Each station can be set to any pair of chutes. On a Small machine with three chutes, there are three possible pairs per station: one and two, one and three, or two and three. On a Medium machine with four chutes, each station has six possible pairs. On Large, ten possible pairs per station. The game starts each station on a random pair, and the starting arrangement is guaranteed not to already be a correct network.

Why fixing one load can ruin another

A comparator has no memory. It cannot behave one way for one load and another way for a different load. Every time it sees two values, it puts the smaller one on top and the larger one on the bottom. That is all it does.

This means a station that fixes the sample you are looking at may undo the sorting done by an earlier station on some other arrangement of parcels. You might tap a station, watch the sample come out perfectly sorted, try another load, and find it worse than before. That is the core of the puzzle: the machine has to work for all loads at once, not one at a time.

How the game checks every load

Checking every load by brute force sounds expensive. Four chutes have twenty-four possible orderings, and five have one hundred and twenty. But a mathematical result called the zero-one principle makes it much cheaper. It says that a comparator network sorts every possible input exactly when it sorts every sequence made only of zeros and ones.

For four chutes, that means checking just sixteen binary sequences instead of twenty-four permutations, and the savings grow fast as chutes increase. The game uses exactly this test. The Loads sorted counter in the stats row is the number of binary sequences the machine handles correctly out of the total.

The reason the shortcut works is that a comparator never invents new values. It only swaps or leaves alone. If any real input comes out wrong, you can turn it into a binary sequence that also comes out wrong by writing zero for everything below a certain threshold and one for everything above. So testing all binary inputs is enough to catch every possible failure.

Strategy: think in bubble passes

The simplest machine that sorts is a bubble sort. Compare the first and second chutes, then the second and third, then the third and fourth, and so on. That single sweep drags the largest parcel to the bottom of the chutes. Repeat the pass and the second largest ends up in its proper place. Keep repeating until every parcel is home.

On a Small machine with three chutes and three stations, the bubble pattern is: join chutes one and two, then two and three, then one and two again. That works for every load. On larger machines the same idea applies: fill the stations with repeated neighbouring-pair passes. It is not always the only solution, but it is almost always a correct one and a reliable starting point when you are stuck.

Strategy: work from the outside in

Once the first pass pushes the largest parcel to the bottom, you know that chute is settled. The next pass only needs to handle the remaining chutes above it. This means later stations can focus on pairs closer to the top.

On a Medium machine with four chutes and five stations, a working arrangement is: join one and two, then three and four, then one and three, then two and four, then two and three. Notice how the first two stations handle the outer pairs in parallel (even though they act sequentially, their effects do not interfere), and the last three sort the middle. Thinking about which positions are already settled helps you avoid wasting stations.

Common mistakes and dead ends

  • Judging by one sample. A machine that sorts three loads in a row can still fail on the fourth. Press Try another load often, and trust the score counter over your eyes.
  • Changing the last station to fix a problem. Whatever reaches the last station is already nearly sorted or is not. Problems have to be solved earlier in the machine, not patched at the end.
  • Joining distant chutes first. Comparing chutes one and five before comparing neighbours is rarely useful. Neighbouring pairs do the heavy lifting in most correct networks.
  • Duplicating a station. Two stations joining the same pair means the second one does nothing every time, because the first already put those two chutes in order. It wastes a valuable station.
  • Giving up after five changes. The machines are small and there are only a handful of pair choices per station. Cycling through them methodically, one station at a time from the first to the last, is faster than guessing at random.
  • Ignoring the score counter. It tells you exactly how many loads still fail. Watch how the count moves each time you tap a station: if it drops, undo the change and try a different pair.

Scoring and what a good result looks like

The game counts changes, and fewer is better. Your best result on each machine size is saved. A perfect score on a Small machine might be three or four changes if you spot the pattern quickly. On a Large machine, getting it right in under fifteen changes is a solid result.

There is usually more than one correct arrangement of stations. Any machine that sorts every load wins. The game does not require a specific solution, just a working one. Experimenting with unusual pair choices can sometimes lead to a correct network that looks nothing like the bubble-sort pattern, which is part of the fun.

No data leaves your device

The stations, the loads, and the zero-one test all run inside your browser. No data is sent to a server. Your best score is stored in this browser's local storage on this device only. There is no account and no leaderboard. Close the tab and the machine is gone.

Help

How to play Sorter

Each station clamps across two chutes and compares whatever arrives on them, sending the smaller of the pair up and the larger down. Tapping a station changes which two chutes it joins. The sample load is only there to watch; the machine is tested against every arrangement the parcels could possibly arrive in before it passes.

Watch the sample

The load on screen shows what the machine does now. Try another load to see whether it was luck.

Change a station

Tap it to cycle which two chutes it joins. Order matters — the stations act one after another.

Read the score

Loads sorted counts how many of the test cases the machine currently handles. It must reach all of them.

Think in passes

Comparing each neighbouring pair in turn drags the largest parcel to the bottom. Repeating that is the simplest machine that works.

The zero-one principle

Checking that a machine sorts everything looks expensive: four chutes have twenty-four possible orders, five have a hundred and twenty, and the count grows as a factorial. There is a much better way. A comparator network sorts every possible input exactly when it sorts every sequence made only of noughts and ones — that is the zero-one principle, and it means four chutes need just sixteen tests rather than twenty-four, with the gap widening fast as chutes are added. The reason it works is that comparators never invent values: if a network ever mis-sorts some input, you can turn that input into a nought-and-one sequence it also mis-sorts, simply by writing nought for everything below a threshold and one for everything above. This game uses exactly that test.

Good to know

A comparator has no memory

It cannot behave differently for different loads. That is why a station fixing the sample may ruin another load entirely.

Neighbouring pairs first

Joining chutes that are next to each other, in order, is the classic pattern. Distant pairs are useful, but rarely as a first attempt.

The last station cannot fix everything

Whatever reaches it is already nearly sorted or is not. Problems have to be solved earlier in the machine.

Try another load often

A machine that sorts three loads in a row can still fail on the fourth. The score tells you the truth; the sample only tells you a story.

Common questions

Do the stations act in order?
Yes, one after another from the first to the last. The same set of pairs in a different order is a different machine.
Can two stations join the same pair?
They can. The second one simply does nothing, which is a wasted station rather than an error.
What counts as sorted?
Smallest at the top, largest at the bottom, on every possible load.
Is there only one machine that works?
No, usually several. Any arrangement that sorts every load wins.
Are sorting networks used in practice?
Very much so — in hardware and on graphics processors, where doing the same fixed comparisons every time is far faster than deciding what to compare next.