๐Ÿ”ฌ Science

Smoothing the Signal

Stardate 55127.2 ยท UES Magnanimous

Briefing

The pattern Lt. Skree filed for long-term observation is real, and it is buried in jitter. Skree wants a moving average: for each position, the mean of that reading and the ones before it in a window of a given size, rounded to two decimal places.

Skree has anticipated the question about the beginning, where a full window does not exist yet, and answers it thus: use what you have. The first value averages one reading, the second averages two, and so on until the window is full. Skree considers this "the only defensible choice" and has already rejected two others in writing.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขA window of two over four readings
  • โ€ขA window of three, with the ramp-up at the start using what exists
  • โ€ขA window of one is the readings unchanged
  • โ€ขA window larger than the whole list averages everything so far at each step
  • โ€ขResults are rounded to two decimal places
Ask Commander Raghunathan for a hint

For position i, average the readings from max(0, i - window + 1) up to and including i. Slicing makes that one line. Round each result to two places, and remember Rust rounds by multiplying, rounding, and dividing.