Given two strings in any default I/O format, do the following:
NOTE: The challenge will refer to the first string as the "data" and the second referred to as the "program".
- Change the program to an infinite string which is just the program repeated infinitely (e.g.
1010101010...). The challenge will refer to this as the "infinite program"
While the data is non-empty, do the following while looping over the infinite program:
a. If the current command is "0", delete the left-most bit in the data. If the data is empty, "0" does not do anything.
b. If the current command is "1", append the next character in the program to the data if the left-most bit in the data is a one.
c. If the data is not empty now, output the data.
Data is the left side of the input and the program is the right side.
100, 0 --> 00, 0 1111, 1 --> 11111, 111111, 1111111, ... 10, 011 --> 0, 0, 0 1110, 011 --> 110, 1101, 11010, 1010...
- The data and program will consist of only 0s and 1s
- For data/programs that do not halt, your program does not need to halt.
- The data and program will not be empty in the input.
- You may have multiple trailing and leading newlines
- Standard Loopholes are forbidden
- You can use any convenient I/O format
As always with code-golf, shortest code wins!