The Manifest
Stardate 55118.4 ยท UES Magnanimous
Briefing
Forty crates were loaded at Starbase 11 and the cargo manifest's total mass field now reads, in full, "crate". Chief T'Kala, who signs for cargo and takes signing seriously, has declined to sign for a mass of "crate".
Ensign Tannenbaum's summing routine, on inspection, adds the first crate to itself forty times and then, for reasons that remain unclear, formats the result as its own name. The Chief would like a number. Any number, provided it is the right one.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขFour crates add up correctly
- โขA single crate is its own total
- โขAn empty hold has a mass of zero
- โขForty identical crates
- โขLarge masses do not lose anything
Objective
Write total_mass(crates): crates is a list of whole-number
masses in kilograms. Return their total. An empty list has a total of 0.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write total_mass(crates: &[u64]) -> u64: the crates' total mass
in kilograms. An empty slice has a total of 0.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
A running total: start at zero and add every crate. Both languages have a one-liner for this (sum, .iter().sum()), and it is worth writing the loop by hand once first.
Debrief
The manifest reads 4,120 kilograms and Chief T'Kala has signed for it. She has also initialled Gerald's entry, since Gerald technically counts as cargo. Gerald weighs four kilograms and is listed as "live plant, do not stack".