Suppose we use the following rules to pull a single string from another string, one containing only ASCII printable characters and called an
*-string. If the string runs out before the process halts, that is an error, and the result of the process is undefined in that case:
- Start with
- Whenever you encounter a
dby 2. Whenever you encounter another character, concatenate it to the end of
sand subtract 1 from
d. If now
d=0, halt and return
d->d 769->7 abcd56->a *abcd56->ab **abcd56->abcd *7*690->769 ***abcdefghij->abcdefgh
Undefined Examples: (note that the empty string would be one of these as well)
*7 **769 *7* *a*b *
Your job is to take a string and return the shortest
*-string that produces that string.
7->7 a->a ab->*ab abcd->**abcd 769->*7*69
Your program should handle any string containing at least one character and only non-
* ASCII printable characters. You can never return strings for which the process is undefined, since by definition they cannot produce ANY strings.
Standard loopholes and I/O rules apply.