Given a string, mark which parts in the string repeat in box brackets, and write how many times it does so before the box.
Example:st st st Hello ThereThere
st(with a space after) repeats 3 times, There repeats 2 times, and l repeats 2 times in Hello, so the output will be:
3[st ]He2[l]o 2[There]
There is no space between [st ] and Hello because the space in the string is being taken up by the repeating part. [st ], 3 times with a Hello after it would be st st st Hello, which is what the string has.
Other examples:
st Hello st st Bye -> st He2[l]o 2[st ]Bye
Bookkeeper -> B2[o]2[k]2[e]per
/\/\/\\\\\\\\/\/\/ -> 3[/\]6[\]3[\/]
Shortestest code wins.
EDIT: To clarify the choice of selections, choose the largest possible repeating section, and try and leave as little non-repeating characters as possible. Do not nest boxed-in sections.
ababababcabcabc->4[ab]2[cab]c?4[ab]c2[abc]?3[ab]3[abc]? What boutabcdefdefghiabcdefdefghi->2[abcdefdefghi]?abc2[def]ghiabc2[def]ghi?2[abc2[def]ghi]? \$\endgroup\$