๐Ÿ“ฆ Ops

Cargo Priorities

Stardate 55149.2 ยท UES Magnanimous

Briefing

Nobody has said the words "abandon ship". Chief T'Kala has, however, asked for the cargo loading order to be worked out "as an exercise", and Commander Raghunathan has asked for it "today", and neither of them is making eye contact with the other.

Each crate has a name, a priority from 1 to 5, and a mass. Load the highest priority first. Among equal priorities, load the lightest first, so more of it fits. The result is just the names, in loading order. It is a sort with two keys, and the second key runs the opposite way to the first, which is the bit that catches people.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขHigher priority loads before lower
  • โ€ขEqual priority: lighter loads first
  • โ€ขBoth rules together on a mixed manifest
  • โ€ขA single crate
  • โ€ขAn empty manifest
Ask Commander Raghunathan for a hint

Sort by a compound key. Python: key=lambda c: (-c['priority'], c['mass']), negating the priority so it runs descending. Rust: sort_by(|a, b| b.priority.cmp(&a.priority).then(a.mass.cmp(&b.mass))).