Candidates rank companies; companies rank candidates back. No prices, no central planner: just deferred acceptance: propose, hold the best offer tentatively, reject the rest, repeat. The result is a stable matching (no pair would rather elope), but it quietly favours whoever does the proposing, and only the proposing side can safely tell the truth. The algorithm behind the real hospital match. Live runs the real Python engine in your browser via Pyodide.
One side (circles) pairs off with the other (squares, filled by how many posts are taken). Scrub the rounds: proposals land, engagements form tentatively and a better offer bumps the old one. The rejection then ripples on. A red ring is an agent the market left unmatched.
Each pair, with the rank every agent gave the partner it ended up with: #left · #right. #1 means first choice.
Average rank of the partner each side receives (lower is better), under both directions. Deferred acceptance hands the proposing side its best stable outcome and the other side its worst.
Random market, both directions, run by the real engine. Watch the proposing side's average rank beat the receiving side's on almost every draw.
When the music stops, check any candidate–company pair: at least one of the two prefers what they already have. That's stability: the matching polices itself, with no contracts and no enforcement.
What stability buysLoad "Who proposes, wins": the same market has three stable matchings, and the algorithm picks whichever end of that range favours the proposing side. Neutral procedure, partisan outcome.
Proposer-optimalityNo proposer can ever gain by misreporting, proved here by brute force, not by theorem. But in "The profitable lie", a receiving company games the match just by shortening its list.
One-sided strategy-proofnessIn "Hospitals & residents", the unpopular hospital fills the same single post (and the same resident goes unmatched) in every stable matching. No mechanism choice can staff the countryside.
The rural hospital theorem