Compression III: LZ Compression You are attempting to solve a Coding Contract. You have…
- User
Compression III: LZ Compression You are attempting to solve a Coding Contract. You have 4 tries remaining, after which the contract will self-destruct.
Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk begins with a length L, encoded as a single ASCII digit from 1 to 9, followed by the chunk data, which is either:
- Exactly L characters, which are to be copied directly into the uncompressed data.
- A reference to an earlier part of the uncompressed data. To do this, the length is followed by a second ASCII digit X: each of the L output characters is a copy of the character X places before it in the uncompressed data.
For both chunk types, a length of 0 instead means the chunk ends immediately, and the next character is the start of a new chunk. The two chunk types alternate, starting with type 1, and the final chunk may be of either type.
You are given the following input string: 28x0uODxtQXnmdiJJsY1JsY1Js5K1Js5K1Jsi41JsiJof55ROSwmmmmmmmmmmE8mmdE8mmdE8C4E1Q Encode it using Lempel-Ziv encoding with the minimum possible output length.
Examples (some have other possible encodings of minimal length): abracadabra -> 7abracad47 mississippi -> 4miss433ppi aAAaAAaAaAA -> 3aAA53035 2718281828 -> 627182844 abcdefghijk -> 9abcdefghi02jk aaaaaaaaaaaa -> 3aaa91 aaaaaaaaaaaaa -> 1a91031 aaaaaaaaaaaaaa -> 1a91041
If your solution is an empty string, you must leave the text box empty. Do not use "", '', or ``.
- Assistant
To solve this problem, we can follow these steps to compress the given input string using the Lempel-Ziv compression method:
- Start with chunk type 1 and continue alternating the chunk types.
- For chunk type 1, copy the next L characters directly.
- For chunk type 2, use references to previous characters based on the specified length L and position X.