Rail Yard Lab
A freight train arrives with its cars in any order, and it has to leave in station order, so each car can be set out at its town in turn. In a rail yard that sorting is done by a switch engine moving cars between side tracks, and a side track is a stack: the engine can only reach the car nearest the switch. Rail Yard Lab gives every student the yard, the engine and a program to write in Blocks or Python. Selection sort and insertion sort stop being lines on a slide and become trips across the yard, and the meters count every one, so two programs that both sort the train can be compared by what they cost.
Using this with a class? Make a free class and add your students yourself: each gets a username and password, with no email or Google account needed. Or give them one join code. Using Google Classroom? Post the link there; with a free class, the link also puts each student in your class, so you see their work. mytekDev is also available from the Google Workspace Marketplace, so your school's Google admin can install it for everyone.A first lesson: Open it on the projector at Level 1 and press play. The starter finds car 1 and takes it to the outbound track, and the two cars between car 1 and the switch go with it, coupled behind it where car 2 belongs. Ask why the engine could not take car 1 by itself. Then move the two cars to a spare track by hand, on the yard board, and take car 1 alone.
Set up a free class Share to Google ClassroomWhat a student actually does
Level 1 runs a starter program that finds car 1 and takes it to the outbound track in one trip. It goes wrong in a way students can see: the engine can only reach the car nearest the switch, so the two cars between car 1 and the switch leave with it. A side track is a stack, and the cars above a car have to move to a spare track first. Students can fix it by hand on the yard board, then in the program.
Level 2 makes the whole train with a loop: for each station, find the car, move the cars above it aside, take it out. Finding the next car and putting it straight into place is selection sort. Level 3 runs two correct plans on an 8-car train and counts the trips. The plan that moves all the cars above a car in one trip wins, 13 trips against 15, even though it moves more cars: in this yard every trip costs 60 seconds before it carries a single car, and each car adds only 4.
Level 4 is insertion sort with a rule the app checks: every car leaves track 1 one at a time and goes straight to its place on the outbound train, and the bigger cars park on track 2 to make room and come back. It takes 12 trips where digging each car out takes 9. Level 5 runs the same program on two trains. The train that arrives backward is its best case, 6 trips; the train already in order is its worst, 16 trips or more, because it comes off the track 6 first and insertion sees it reversed.
Level 6 is the Inglenook sidings, a shunting puzzle model railway builders have played for decades: sidings of 5, 3 and 3 cars and a headshunt that holds only 3. Students solve it by hand or by program, and the card says when they found the fewest trips, 10 for this start. Level 7 hands over a train with two cars swapped and asks for the fix: 4 trips at the fewest. Bubble sort needs a swap like that for every pair out of order, which is why yards never sort by swaps.
Levels 8 and 9 move to a hump yard: the engine shoves the train over a small hill and each car rolls down to the track the program picks. A track pulled back over the hump comes out in the order its cars rolled in, a queue where a flat track was a stack, and selection over the hump takes 21 humpings for 6 cars on any train, even one already in order.
Programs drive with yard.move(from_track, to_track, count) and read the yard for free: where a car is, how many cars are above it, which spare track has room, how many cars on a track are bigger than a number. The meters count engine time, trips and car moves, and the yard board lists every track's cars, so a student can check the program against the yard at any moment.
Level 6, the Inglenook sidings: a famous shunting puzzle. Every move goes through a headshunt that holds only 3 cars, and this start takes 10 trips at the fewest.
What they are learning while they work
Nothing here is presented as a lesson. This is what the levels are made of.
| What the student does | What it is |
|---|---|
| Moves two cars away before car 1 can leave | A stack. Only the car nearest the switch can come off a side track: last in, first out. The cars above a car have to go somewhere first. |
| Writes find the car, move the cars above it, take it out, in a loop | Selection sort. Find the next car in order and put it straight into its place, once for every station. |
| Counts 13 trips against 15 for two correct plans | Comparing algorithms by cost. Two programs that both sort the train can cost very different amounts. Counting the costly step, the trip, compares them without a stopwatch. |
| Parks the bigger cars, places the new one, brings them back | Insertion sort. Each car goes into its place among the cars already sorted, and the ones in its way move twice. |
| Runs one program on a backward train and a train in order | Best case and worst case. The same program can take 6 trips or 16 and more on trains of the same length. What the input looks like decides the work. |
| Plans every trip through a headshunt that holds 3 cars | Search under constraints. When only a few moves are possible, the fewest trips come from planning ahead: which car has to be at the dead end next, and what has to move first. |
| Fixes two swapped cars in 4 trips | Why the cost model matters. Bubble sort swaps neighbors once for every pair in the wrong order. Where a swap costs several trips, that makes it a poor choice. |
| Pulls track 2 back and sees 4, 5, 6 come out in the order they rolled in | A queue. A pulled hump track gives back the first car in first, the opposite of a flat track's stack. The same cars, a different structure, a different order. |
| Writes yard.move(track, "out", above + 1) | Variables and functions. A program asks the yard where a car is and how many cars are above it, keeps the answers in variables, and uses them in the next move. |
How to tell whether it landed
Ask, and let them show you in the yard or on the board. A student who has understood it can answer these without help.
- Why did car 1 not leave by itself on Level 1, and what had to happen first?
- Your Level 2 program finds a car and digs it out. Why is that called selection sort?
- One plan on Level 3 moved more cars and still took less engine time. How?
- Why do the bigger cars move twice in insertion sort, and when do they not have to move at all?
- Level 5's train that was already in order took the most work. Why, in this yard?
- Why do yards not fix a train by swapping cars that are out of order?
- Why does a track pulled back over the hump come back 4, 5, 6 and not 6, 5, 4?
Use it in your subject
Not a technology class? Then the app is how students show what they learned in your unit. More projects for every subject.
Computer science (CSTA 3B-AP-10, 3B-AP-11, 3B-AP-12)
Stacks, selection and insertion sort, comparing two correct algorithms by the cost of their steps, best and worst cases, and a search for the fewest moves.
AP Computer Science Principles and A
Algorithm efficiency measured by counting steps (AAP-4.A), and selection and insertion sort as students write them in AP CSA, run on a yard where each step has a visible cost.
Math
Counting pairs out of order, comparing totals of trips and seconds, and why a fixed cost per trip makes fewer, larger trips cheaper.
Transportation and logistics
How freight is classified in a yard: arrival and outbound tracks, switches, cuts of cars, and why a yard plans its moves.
Practical notes
- AgesGrades 8 to 12. Levels 1 and 2 need only a loop; insertion, best and worst cases and the cost comparison fit high school CS and AP classes.
- TimeLevels 1 and 2 fit in a class period. Levels 1 to 9 take about four periods.
- EquipmentA computer or Chromebook with a modern browser. Nothing to install.
- CostFree. The app has no paid tier and no AI.
- PrepRun Level 1's starter once, then make the train by hand on the yard board. Read How it works in the Help menu: it is one screen.
- In a groupOne yard per student, or pairs: one writes the program, one watches the board and calls out the cars above each one before it runs.
For classes that will never stand in a rail yard
A classification yard is closed to visitors, and the sorting it does is hard to see from a road. Here every student runs a yard at once, sees each trip happen, and finds out for themselves why the cars above have to move first and why the plan with fewer trips wins. Nobody stands on the tracks, nothing derails, and a car sent to a full track stops at the switch.
Common questions
Is it free?
Yes. Rail Yard Lab has no paid tier, and it can be tried right on this page without an account. Saving needs a free account.
Does it work on a Chromebook?
Yes. It runs in the browser with nothing to install.
Do students need to know how to code?
No. Level 1 runs a starter program, every level can be tried by hand on the yard board first, and the Blocks tab is drag and drop. Python is there for students who want it, and the Python tab shows what the blocks say.
Are the numbers real?
One car slot is 60 feet, about a 50-foot boxcar over its couplers. A trip costs 60 seconds plus 4 seconds a car: these are round numbers chosen so trips can be counted, and the Help says so. A real switching move takes longer. The Inglenook sidings are the standard layout of the puzzle, and the fewest trips the app reports were checked by searching every position.
What does it simplify?
One engine works the yard, with no crew, grades or brakes, and every trip costs the same however far it goes. Cars are drawn shorter than 60 feet so a whole train fits the screen. Nobody is hurt: nothing derails, and a car sent to a full track stops at the switch.
Are more levels coming?
Yes. Levels 1 to 9 are open: the stack, selection sort, counting trips, insertion sort, best and worst cases, the Inglenook, the swap, and a hump yard, where a track pulled back is a queue and selection takes the same number of humpings on any train. The levels listed after them in Missions, the sorting methods real hump yards use and merging two trains, open in later versions.
Can students share their work?
Yes. A project saves every level's best run and the program, with a picture of the yard. Typed words in a shared project, its name and the program, pass the platform's filter.
Still have a question? Ask us, and a person will write back.
Where to go next
Start with Rail Yard Lab
Trying it costs nothing and takes about five minutes. An account is what makes the work last.
Rail Yard Lab is one of the making apps on the platform. Every level runs on one model of the yard and its costs, so the selection sort a student writes on Level 2 is the plan whose trips they count on Level 3.
Page last reviewed December 2026.
Google, Google Classroom and Chromebook are trademarks of Google LLC.