Rail Yard Lab teaching notes
For high school computer science teachers, AP CSP and AP CSA included. These notes cover a first period, the levels, the misconceptions the app is built to confront, and what it leaves out.
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 Classroom- About these notes
- A first period
- The levels
- What students get wrong, and where the app answers it
- What the app simplifies, on purpose
- Setting it up for a class
- Standards
About these notes
Rail Yard Lab is a small freight yard and a switch engine, programmed in Blocks or Python. A train arrives on track 1 with its cars in any order, each car numbered with its station, and the program makes the outbound train in station order, car 1 at the front. Two spare tracks give the engine room to work, and the yard board lists every track's cars.
Levels 1 to 9 are open, and each saves its best run. Levels 1 to 7 are a flat yard and the Inglenook puzzle; Levels 8 and 9 are a hump yard, where the engine shoves the train over a small hill and each car rolls to its track. The levels after them in Missions, the sorting methods real hump yards use and merging two trains, open in later versions. Every level can be tried by hand on the yard board before it is programmed.
A first period
Levels 1 and 2 fit in a period, with time to talk about why the engine cannot reach a buried car.
- Run the starter (10 minutes) Open Level 1 and press the round play button or the space bar. The starter finds car 1 and takes it to the outbound track in one trip, and the two cars between car 1 and the switch go with it, coupled behind it where car 2 belongs. Ask why.
- Do it by hand (10 minutes) Press Reset. On the yard board, click car 4 (it and car 3 are the cut), then Track 2. Then click car 1, then Outbound. Two trips. Name the idea: a side track is a stack, and the cars above a car have to move first.
- Fix the program (15 minutes) Back in Blocks, move the cars above car 1 to a spare track before taking car 1. The blocks are cars above car, in Reading, and a spare track, in Tracks.
- The whole train (10 minutes) Open Level 2. Put the steps for one car inside a loop that counts through every station, and use the loop's number where the program says car 1. The finish card names it: selection sort.
The levels
Each level opens with one idea and a card that says what to do. The meters count engine time, trips and car moves (a trip of three cars is three car moves), and the finish card compares the run with another plan.
| Level | The job | What it is built to show |
|---|---|---|
| 1. Dig it out | Get car 1 to the front of the outbound train | A side track is a stack: only the car nearest the switch comes out |
| 2. One car at a time | Make the whole outbound train with a loop | Selection sort: find the next car, move the cars above it aside, take it out (8 trips moving them in one trip, 11 one at a time) |
| 3. Count the trips | Run two correct plans on an 8-car train | Comparing algorithms by cost: 13 trips against 15, and the faster plan moved more cars |
| 4. Slot it in | Insertion sort, with a rule the app checks | Each car goes straight to its place; the bigger cars park on track 2 and come back, so they move twice (12 trips, where digging out takes 9) |
| 5. The backward train | The same program on two trains | Best and worst case: 6 trips on the backward train, 16 or more on the train already in order |
| 6. The short headshunt | The Inglenook sidings, by hand or by program | Planning under tight limits: sidings of 5, 3 and 3 and a headshunt of 3; this start takes 10 trips at the fewest |
| 7. Why not swap | Mend a train with cars 4 and 5 swapped | 4 trips for one swap: bubble sort needs a swap for every pair out of order, so yards never sort by swaps |
| 8. Over the hump | Make the train on track 1 in a hump yard | A queue: a pulled hump track comes back in the order its cars rolled in, 4, 5, 6 (9 humpings, 1 pull) |
| 9. One car per pass | Selection over the hump | Every pass rolls every car still on the lead and keeps one: 21 humpings for 6 cars on any train, 78 for 12 |
Programs move cars with yard.move(from_track, to_track, count) and read the yard at no cost: yard.find(car), yard.track_of(car), yard.above(car), yard.spare(track), yard.cars_on(track), yard.top(track), yard.space(track), yard.count_bigger(track, number), yard.count() and yard.done(), with the meters yard.time(), yard.trips() and yard.moves(). Tracks are 1, 2, 3 and "out"; in the Inglenook the headshunt is "head". In the hump yard, Levels 8 and 9, tracks are 1 to 4: yard.hump(track) rolls the next car onto a track, yard.pull(track) pulls a track back to the lead once the lead is empty, and yard.lead(), yard.next_car() and yard.smallest_on_lead() read it. Each yard keeps its own program. There is no sort command: the plan is the student's.
What students get wrong, and where the app answers it
| What students think | Where the app answers it |
|---|---|
| Any car can be taken off a track | Level 1: the starter takes car 1 and the two cars above it go too. Only the car nearest the switch is reachable. |
| A sort is one command | Level 2: there is no sort. The loop finds a car, clears the cars above it and moves it, once per station. |
| The plan that moves fewer cars is faster | Level 3: the plan with more car moves takes fewer trips and less engine time, because each trip costs a minute before it carries anything. |
| An algorithm takes the same work on every input | Level 5: one program takes 6 trips on one train and 16 or more on another of the same length. |
| Already in order is always the easy case | Level 5: in this yard the train in order comes off track 1 with car 6 first, so insertion sees it reversed and does the most work. On a list read front to back, sorted input is insertion's best case. |
| Every list gives its items back last in, first out | Level 8: a flat track is a stack, but a pulled hump track comes back first in, first out, a queue. The cars rolled 4, 5, 6 and come back 4, 5, 6. |
| Swapping two cars out of order is quick | Level 7: one swap takes 4 trips at the fewest. Bubble sort's swaps, one for every pair out of order, would cost far more than digging each car out. |
What the app simplifies, on purpose
- Every trip costs the same, 60 seconds plus 4 seconds a car, however far it goes. Real switching moves take longer and vary.
- One engine works the yard, with no crew, grades, brakes or radio. Nobody stands on the tracks, nothing derails, and a car sent to a full track stops at the switch.
- One car slot is 60 feet, about a 50-foot boxcar over its couplers, but the cars are drawn shorter so a whole train fits the screen.
- The arriving train stands on track 1 with car order given from the dead end; how the road crew put it there is not shown.
- The Inglenook accepts the three spare cars left in the headshunt at the end; the classic puzzle wants them on a siding. The fewest trips for Level 6's start is 10 either way.
- The hump is drawn 4 m high and every rolling car stops in the right place; a real yard's retarders, and its crews, see to that. A humping takes 15 seconds, a big hump yard's real pace; a pull's 90 seconds and 4 a car are round numbers.
- The engine pulls a track back only once the lead is empty, because it is behind the train it shoves.
- Reading the yard is free: a program can ask where any car is without a crew member walking out to look.
Setting it up for a class
No setup is needed. With free accounts, each student's levels, best runs and program save as one project, with a picture of the yard. Typed words in a shared project, its name and the program, pass the platform's filter.
Faster and Slower change only how fast the clock runs on the screen; the trips and engine time do not change. The camera buttons switch between the whole yard, the yard tower and a ride on the engine. How it works, in the Help menu, is one screen and covers the rules a student needs.
Standards
- CSTA 3B-AP-10: use and adapt classic algorithms, selection and insertion sort, to make the train.
- CSTA 3B-AP-11: evaluate algorithms by their efficiency, counting trips and engine time on Levels 3 to 5 and 7.
- CSTA 3B-AP-12: a stack and a queue as data structures, on every flat track from Level 1 and every hump track from Level 8.
- AP CSP AAP-4.A: algorithmic efficiency, by counting the steps two correct algorithms take.
- AP CSA: selection and insertion sort, written by the student and run on the yard.
Levels 1 and 2 need only a loop and a variable. Levels 3 to 9 fit high school CS and AP classes, where comparing algorithms by their cost is the point.
More help
Is something on this page wrong or not clear? Write to us.
Page last reviewed December 2026.
Google, Google Classroom and Chromebook are trademarks of Google LLC.