Dependency Sorter — Algorithms

Build the village guard post part by part: 18 levels of topological sort, Kahn's algorithm, dependency graphs and cycle detection.

What you learn in this game

Many things must happen in a certain order: a module is built after its dependencies, a course is taken after its prerequisites, a package is installed after what it needs. Topological sort produces that order. The rule (Kahn's algorithm): repeatedly take a node whose dependencies are all already placed. On this pos ronda every node is one part of the building, and the parts that are ready light up: tap them one by one until everything stands.

When dependencies form a loop (a needs b, b needs c, c needs a), there is no valid order: every node waits for another forever. This is a circular dependency, a real bug in module imports and build systems. Kahn's algorithm detects it: if at some point no node is ready while nodes still remain, the rest are locked in a cycle. Place everything you can first, then press "Cycle!" when stuck.

A cycle needn't swallow the whole graph: it can hide among healthy nodes. Strategy: run Kahn as usual, placing every node that becomes ready. If at the end some nodes remain with none ready, those are the ones locked in a cycle. Place what you can first, then declare a cycle for the rest.

What the levels ask

  1. Place each module only AFTER everything it needs.
  2. core first; then the two modules (any order); render last.
  3. Sequence all six; keep each chain in order.
  4. base first; then three modules (any order); bundle last.
  5. Place dist only after all three sources are done.
  6. Take a course only after its prerequisites.
  7. Always pick a stage whose dependencies are complete.
  8. Try to sequence. If nothing is ready while nodes remain, press "Cycle!".
  9. Pick ready nodes in turn until complete.
  10. Place everything ready; if the rest is locked, declare a cycle.
  11. Install a package only after all its dependencies are installed.
  12. Place what you can; declare a cycle for the rest.

And more, 18 levels in all.