Inventory Reconciliation
Stardate 55134.1 ยท UES Magnanimous
Briefing
Chief T'Kala has done a physical count of Stores, with a torch, and would like it compared against the computer's idea of Stores. She wants a list of every item where the two disagree, with how far off the computer is: actual minus expected, so a shortfall is negative. Items that agree should not appear at all; she does not need to be told what is fine.
Items in one list but not the other count as zero in the list they are missing from. Ensign Tannenbaum asked whether that was "a bit harsh". The Chief said the torch does not lie.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขItems that differ, with actual minus expected, sorted by name
- โขItems that agree are left out entirely
- โขAn item missing from the actual count is a shortfall of the full amount
- โขAn item missing from the expected list is a surplus of the full amount
- โขTwo identical inventories produce nothing
Objective
Write reconcile(expected, actual): both are dicts of item name to count.
Return a list of (name, difference) tuples for every item whose counts
differ, where difference is actual - expected. A name absent
from either dict counts as 0 there. Sort the result by name.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write reconcile(expected: &[(&str, i32)], actual: &[(&str, i32)])
-> Vec<(String, i32)>: each input is a list of (name, count)
with unique names. Return (name, actual - expected) for every item whose
counts differ. A name absent from either side counts as 0 there. Sort by name.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Take the union of the names from both sides, look each up with a default of zero, and keep the ones where the numbers differ. Sort by name at the end so the order is stable.
Debrief
Three discrepancies. Two are rounding. One is a case of forty coffee filters that does not exist on any manifest and that nobody will explain. Chief T'Kala has logged it as "found property" and moved it nearer the replicator.