We have come up with a compression technique for lowercase text that contains a lot
of repetition. We will use 'R' to mean repeat the preceding text. The area to
be repeated will be all the text since the closest preceding 'M' (or since the beginning of
the text if there is no preceding 'M').
For example, "abcabcdabcabcdxyxyz" could be expressed in compressed form
as "abcRdRMxyRz".
To decompress this, the beginning abc is first repeated to become "abcabc",
then "d" is added, and then all of that is repeated to make "abcabcdabcabcd".
This is followed by the "xy" which is repeated and followed by the "z".
Create a class Repeat that contains a method minLength that is given the text to
be compressed and that returns the minimum number of characters that can be used
to express it with this compression technique. Of course all the 'R' and 'M'
characters must be counted.
|