The Hottest Reading
Stardate 55119.9 ยท UES Magnanimous
Briefing
The engineering display is meant to show the hottest of the eight coolant loops so that whoever is on watch knows where to look first. It shows loop one. It always shows loop one. Loop one is, in fact, the coldest, and has been for a month.
Commander Raghunathan found the routine returns the first reading rather than the largest. Lt. Skree has added that when there are no readings at all, the display shows "-1 degrees", which Skree describes as "a temperature that is also a lie". The Commander would like the real maximum, and nothing at all when there is nothing to measure.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขThe largest of several readings
- โขA single reading is the maximum
- โขThe maximum is not the first reading
- โขAll negative readings: the least negative wins
- โขNo readings at all: nothing, not a made-up number
Objective
Write hottest(readings): return the largest number in the list, or
None if the list is empty.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write hottest(readings: &[i32]) -> Option<i32>: the largest
reading, or None if the slice is empty.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Keep the best-so-far as you walk the list, and start it from the first element, not from zero, or the all-negative case will bite. Python returns None for empty; Rust returns an Option, and .iter().max() already does exactly this.
Debrief
The display shows loop six, at 71 degrees, which is where Commander Raghunathan has been standing with a torch for a month. When there are no readings it now shows nothing, which Lt. Skree has approved as "the only honest thing it has ever displayed".