11
Challenge
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.
10
-->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.
Test Cases
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...
Notes
- 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!
@Sanchises Seems like a borderline duplicate to that, but you have to get the result at a certain generation and that is for any cyclic tag system. – MilkyWay90 – 2019-04-07T17:49:05.683
in the first test case,
100
goes to10
on cmd0
, whose definition is "delete the left-most bit in the data." wouldn't the leftmost bit of100
be1
? – Jonah – 2019-04-07T17:52:09.667@Jonah Oh, missed that – MilkyWay90 – 2019-04-07T17:55:09.527
in case (b), if you do the append, does the instruction pointer move right one or two characters? – Sparr – 2019-04-07T18:08:47.607
@Sparr It moves right one. See the section labeled Challenge. – MilkyWay90 – 2019-04-07T18:11:48.883
Your example submission produces a different result on the last test cast than what you have listed above in the post. Your example program's output matches my program's output, so I expect the flaw is in the test case – Jonah – 2019-04-07T18:55:51.780
@Jonah Sorry, forgot that one too. I keep on forgetting that 0 removes the left-most data bit, not the right-most one – MilkyWay90 – 2019-04-07T18:56:53.137
I read "You can use any convenient I/O format" and used lists of zeroes and ones. I'm noticing now that "any convenient format" conflicts with the "Given two strings" requirement. I've already submitted my answer, but you may want to clarify this for others. – Jonah – 2019-04-07T19:08:55.793
@Jonah I can't come up with a way to rephrase the question, can you help? – MilkyWay90 – 2019-04-07T19:11:06.067
I would just say "Given two strings, two lists of booleans, or other equivalent format, ..." in the first sentence. – Jonah – 2019-04-07T19:12:29.240
Are we allowed to have multiple trailing newlines? – Embodiment of Ignorance – 2019-04-07T20:48:21.260
@EmbodimentofIgnorance Yes – MilkyWay90 – 2019-04-07T21:45:18.943
@Jonah technically in math a string is just a list of symbols :P so a list of anything is a string :P – ASCII-only – 2019-04-08T01:01:30.917
@MilkyWay90 "see the section labeled Challenge" is not a great response when I am asking a question specifically already referring to that same section. – Sparr – 2019-04-08T23:37:28.293
@Sparr Oh yeah, didn't notice that. Sorry! – MilkyWay90 – 2019-04-09T00:34:23.983