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
Put this on your class site

Students can use Rail Yard Lab right on your page, with no account. What they make stays on that page; to keep their work, they make a free account.

Google Sites: Insert, then Embed, then By URL, and paste this address.

https://mytekdev.com/try/railyardlab?embed=1

Canvas, a blog, or any page that takes HTML: paste this code where you edit the page as HTML.

<iframe src="https://mytekdev.com/try/railyardlab?embed=1" width="100%" height="640" style="border:0" allow="fullscreen" title="Rail Yard Lab demo from mytekDev"></iframe>

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.

Every trip costs 60 seconds before it carries a car, and each car adds 4 seconds. These are round numbers chosen so trips can be counted, and the app says so. Because a trip's fixed cost is large, the plan with fewer trips wins even when it moves more cars, and that one fact drives most of what the levels show.

A first period

Levels 1 and 2 fit in a period, with time to talk about why the engine cannot reach a buried car.

  1. 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.
  2. 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.
  3. 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.
  4. 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.

LevelThe jobWhat it is built to show
1. Dig it outGet car 1 to the front of the outbound trainA side track is a stack: only the car nearest the switch comes out
2. One car at a timeMake the whole outbound train with a loopSelection 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 tripsRun two correct plans on an 8-car trainComparing algorithms by cost: 13 trips against 15, and the faster plan moved more cars
4. Slot it inInsertion sort, with a rule the app checksEach 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 trainThe same program on two trainsBest and worst case: 6 trips on the backward train, 16 or more on the train already in order
6. The short headshuntThe Inglenook sidings, by hand or by programPlanning 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 swapMend a train with cars 4 and 5 swapped4 trips for one swap: bubble sort needs a swap for every pair out of order, so yards never sort by swaps
8. Over the humpMake the train on track 1 in a hump yardA 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 passSelection over the humpEvery 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 thinkWhere the app answers it
Any car can be taken off a trackLevel 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 commandLevel 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 fasterLevel 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 inputLevel 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 caseLevel 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 outLevel 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 quickLevel 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

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

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.