/// is an esoteric language, and I thought of posting a code-golf problem related to it.
A /// program of the form /p/q/r
where p, q, and r are strings that do not contain /
or \
does:
- If the string p is a substring of r, go to step 2; otherwise step 5.
- Replace the leftmost occurrence of p in r with q.
- Let the result of step 2 be the new r.
- Go to step 1.
- Output r and halt.
In step 1, an empty string shall be a substring of any strings.
For simplicity I am thinking each of p, q, r consisting of zero or more a
's and b
's.
At first I thought the following algorithm would work:
- Returns no if p is both a substring of q and r; otherwise yes.
But that was wrong; /ab/bbaa/abb
can be one of the exceptions, as "ab" does not appear in "bbaa" but in "abb".
I am suspecting it's possibly impossible to make an algorithm to solve this problem. Is it solvable?