๐Ÿ”ฌ Science

Signal Compression

Stardate 55152.4 ยท UES Magnanimous

Briefing

The spikes in both logs, ours and theirs, are a message. It is long and mostly repetition, and Lt. Skree wants it run-length encoded so the structure is visible: "aaabcc" becomes "a3b1c2", each character followed by how many times it repeats in a row.

Commander Raghunathan looked at the first compressed line and did not say anything. Skree asked whether the compression was wrong. The Commander said it was right, and that was the trouble.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขRuns of repeated characters are counted
  • โ€ขA single character has a count of one
  • โ€ขRuns longer than nine digits correctly
  • โ€ขNon-letters and spaces are encoded like anything else
  • โ€ขAn empty message compresses to an empty message
Ask Commander Raghunathan for a hint

Walk the string keeping the current character and a count. When the character changes, emit the previous character and its count and reset. Do not forget to emit the final run after the loop ends; that is the classic slip.