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
Objective
Write compress(text): run-length encode text, so each run of
identical characters becomes the character followed by the run length. So
"aaabcc" becomes "a3b1c2". An empty string returns an empty
string.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write compress(text: &str) -> String: run-length encode
text, so each run of identical characters becomes the character followed by
the run length. So "aaabcc" becomes "a3b1c2". An empty string
returns an empty string.
Press Run Diagnostics and I will tell you which objectives you actually met.
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.
Debrief
Compressed, the message is nineteen characters long. It is a stardate, and it is tomorrow's. Beneath it, in both logs, is a second line that Skree has compressed to "n1o1t1 1y1e1t1". Skree has read this aloud. Nobody on the bridge has said anything for some time.