I Know What I Need, But I Don't Know How To Build It
Pick the thing you need. Then derive it: meaning, state, operations, rules, examples, representation, pseudocode — and only then the code, one rung at a time.
“I know I need a shopping cart. I have no idea how to implement a shopping cart.” The gap is not a missing tutorial; it is a missing method. Every stage below asks you to write before it shows you anything, because the code is the last step of a derivation, not the first thing to search for.
Which concept?
Grouped by exercise level; the level is how far the derivation goes, not how hard the code is.
How much help?
Every stage's content is shown right after your attempt box.
Inventory — twelve stages
I know I need inventory tracking. I have no idea how to implement it so that two people cannot buy the last unit.
Define the concept
In one sentence, without any code: what is it? Then answer for yourself — does it have identity, who owns it, how long does it exist, should it survive a reload or a login?
Inventory = The quantity of each product that is actually available to sell, kept truthful as units arrive, are promised to buyers, and leave.
- Does an inventory record have identity? It borrows the product's. There is exactly one stock record per product; two records for the same product would be two sources of truth for one number, which is the failure the concept exists to prevent.
- Who owns it? The business, not a buyer. A buyer only ever holds a reservation — a promise of some units — and the reservation belongs to that buyer. Ownership of the count and ownership of a promise are different things and appear as different state.
- How long does it exist? As long as the product is sold. A reservation is much shorter-lived: it is created at "add to cart" or "begin checkout" and ends when it is consumed by an order or released — by cancellation or by expiry.
- Should it survive reload? Always. A count that resets to its starting value is a count that sells the same unit again. Inventory is the concept where in-memory is only ever V0 and V1, never a destination.
- Does it depend on who is asking? No. Available is the same number for Alice and Bob — which is precisely why they can race for it.
The catalog is one derivation, not the only one (impl §60). A different set of examples yields different rules; a different first requirement yields a different V1; a map instead of an array is not wrong, only an answer to a different question. Compare your derivation with the reference for the differences, then decide which ones were rules and which were style.
Take it further
The flagship exercise: the cart typed by you, with the reference hidden until you ask.
Make It Smaller Until You Know How to Build It →The principle behind the ladder, and the primitive chain it produces.
The Implementation Loop →The loop the twelve stages follow, and why the code is last.