Lori Shunting — Data Structures

Couple and unhook cane lori in the yard: arrays, linked lists, doubly linked lists, union-find. 16 levels, played right in the browser with nothing to install.

What the levels ask

  1. The milling season begins. Buku Lori keeps the records of eight lori twice: urut (an array, in order from the engine back) and menurutNo (an object keyed by hull number). Pak Tono asks for a lori by its place and for a lori by its number. Fill keUrutan and cariNo so every answer is right and takes one step.
  2. Each lori that finishes loading is coupled at the back end of the train, and Mas Fajar writes the order down for the mill. The train is kept as the array lori. Fill gandeng so the order is the loading order. The tablet also counts every slot of the array written: over the season (300 lori), each coupling may write only one slot.
  3. Empty lori wait on the siding until they are called, and their order does not matter. Bang Jaya pulls out a lori by its number to take it to the plots. Fill tarik so that lori leaves, no empty slot is left, and over the season each pull writes at most 2 slots.
  4. The weighbridge rejected four lori for dirty cane, and Pak Sastro brings the list. lepasDitolak walks the array lori and unhooks each rejected lori with splice. Fill the head of the for loop so every rejected lori comes off.
  5. From today the train is kept as a linked list: each Lori keeps its number and next, the lori behind it, and head points at the lori right behind the engine. A newly loaded lori is coupled at the front. Fill gandengDepan so the new lori becomes the first and the whole old train stays coupled behind it.
  6. Nenek Marni is looking for the lori with her cane. cari walks from the engine back along next and returns the lori, or null if it is not there. Fill the pointer used to walk (the hole p, in four places) so the lori is found and the train is still whole after the search.
  7. Pak Tono's lori was loaded late and must be coupled right behind lori 25, in the middle of the train. sisipSetelah finds that lori (depan) and makes the new lori. Fill its last two lines, in order, so the new lori goes in and the lori behind depan still come along.
  8. Pak Harun drives a pushing engine at the back, so the train must be walkable from both ends: each lori now has prev and next, and the train has head and tail. Fill gandengBelakang for the empty train and for the coupling back, so the lori are the same from the front and from the back.
  9. Lori 25 has a broken axle. The shunter already holds that lori, so it does not have to be found. Fill the two lines of lepas so its two neighbours hold each other, and the broken lori can no longer be reached from the front or from the back. Today a lori at the front end and one at the back end come off too.
  10. Bu Asih's lori must go right in front of the lori the shunter is holding. sisipSebelum has already set the new lori's prev and next. Fill its last two lines, in order, so the new lori shows from the front and from the back.
  11. During the milling, portable rails are laid between the cane plots. Each plot has a sign pointing at another plot (parent); a plot whose sign points at itself is the end of its network. Rara asks which plots are already joined. Fill union and tersambung so every answer is right.
  12. Bang Jaya joins three hundred plots over the season, one by one to a network that keeps growing. The tablet only handles 4,000 sign reads a season, and the tallest sign tree may be at most 8 levels. Fill union so the smaller network always hangs under the bigger one, and its size is kept at the right end.

And more, 16 levels in all.