This is inspired by Monday Mini-Golf #6: Meeesesessess upp teeexexextext
ETHproductions have difficulty entering text on his usual webpage. Whenever he use digits or letters, the text will be meeesesessessesseesseessedessed up. Your task is to help him type so the normal behavior is achieved.
The transform affects runs of alphanumeric (
[0-9A-Za-z]) characters delimited by any nonalphanumeric characters. In the following example, the first line would be transformed into the second (the other lines show the breakdown of the transform)
An12num: Annn1n12n12nn12nn12nun12nun12numn12num A nn n1 n12 n12nn12n n12nun12nu n12numn12num
In particular, any alphanumeric character after the first in a run will be transformed into the entire run so far except for the first character. Furthermore, if the character is a letter (as opposed to a digit), the character will be turned into twice the run.
Thankfully, backspace will delete last character and also resets the beginning of the run.
This time your task is not to perform the transformation. Instead, given an input string, you must return an encoded text that, if transformed, will result in the input. The output must be as short as possible, where
\<char> counted as a single character.
Text is encoded as follows:
\ -> \\ backspace character -> \b linefeed -> \n
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
Each test case is two lines, the first being input, the second output.
Heeeeeelp me. It shouldn't be messed up. Hee \blp\b me\b. It\b sh\bou\bld\bn't be\b me\bss\bed\b up\b. alert("Hello, world!"); al\ber\bt("He\bll\bo, wo\brl\bd!"); 1223234234523456 123456