Signal Cleanup
Stardate 55121.3 ยท UES Magnanimous
Briefing
Welcome to the Science station. Lt. Skree has been waiting for you, in the sense that Skree has been standing very still by the console for some time.
The long-range array delivers readings in the order it takes them. Most are below the noise floor. Skree wants every reading above a threshold, in their original order, and has been extremely specific that "above" means strictly greater than: a reading equal to the floor is noise, by definition, and Skree has the definition printed out.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขKeeps only readings above the threshold, in order
- โขA reading equal to the threshold is noise and is dropped
- โขNothing above the threshold: an empty result
- โขEverything above the threshold: the whole list, unchanged
- โขNegative thresholds work too
Objective
Write above_threshold(readings, threshold): return a new list of the
readings that are strictly greater than threshold, keeping
their original order.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write above_threshold(readings: &[i32], threshold: i32) ->
Vec<i32>: the readings that are strictly greater than
threshold, in their original order.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Build a new list containing each reading that passes the test. Do not modify the input while walking it. A comprehension or filter is the natural shape; a loop with append is just as good.
Debrief
Skree has the filtered signal and has said "adequate", which the crew has learned to receive as effusive praise. There is a faint pattern in the readings. Skree has filed it under "pending long-term observation" and gone to lunch, which Skree does at exactly the same time every day.