14
0
A cyclic tag system is a tiny, Turing-complete computational model consisting of a two-symbol alphabet (I'll use {0,1}
), a finite, nonempty cyclic list of productions that consist of those two symbols, and an unbounded word which also consists of those two symbols.
At each step:
- the first element in the word is removed
- if it was
0
the current production is skipped - if it was
1
the current production is appended to the end of the word. - the next production becomes active. If this was the last production, go back to the first one.
The system halts when the word becomes empty.
An example (from Wikipedia):
Productions: (010, 000, 1111)
Initial word: 11001
Generation Production Word (before) Word (after)
0 010 11001 → 1001010
1 000 1001010 → 001010000
2 1111 001010000 → 01010000
3 010 01010000 → 1010000
4 000 1010000 → 010000000
5 1111 010000000 → 10000000
6 010 10000000 → 0000000010
7 000 0000000010 → 000000010
8 1111 000000010 → 00000010
9 010 00000010 → 0000010
Your task, if you choose to accept it, is to write a program or function that takes:
- a list of productions,
- the initial word, and
- a generation,
and prints or returns the word at that generation.
For example,
cyclic_tag(
prod=[[0,1,0],[0,0,0],[1,1,1,1]],
word=[1,1,0,0,1],
gen=4) => [1,0,1,0,0,0,0]
Implementation details:
The alphabet does not matter. You may use
0
and1
,True
andFalse
,T
andNIL
,A
andB
, or even1
and0
, or whatever else you may come up with, as long as you are consistent. All input and output must use the same alphabet, and you must indicate what you are using for0
and what for1
.The length of the word must be theoretically unbounded. That is, you may not hardcode a maximum word length. If I run your program on an ideal computer with an infinite amount of memory, your program must theoretically be able to make use of it. (You may ignore your interpreter's/compiler's limits.)
If the given system halts before the given generation is reached, you must return or print the empty word.
The empty production exists, and you must be able to handle it. If you write a full program, your I/O must also be able to handle it.
Edit: I had originally intended for generation 0
to be the input word itself, and generation 1
to be the result of the first step. I.e., I had intended for you to return the before column. However, as I have not been clear enough in stating this, I will accept both options; for each generation you may return the value in either the before or the after column. You must state that you are following the after column, if you are doing so. You must also be consistent in which column you choose.
I will award the smallest code a week from now (10/27/2014).
Um, are you sure your output in the example is correct? Based on the other example you gave, I think that is gen 5... – FryAmTheEggman – 2014-10-25T02:44:24.417
Can we take the input in a different order? – Martin Ender – 2014-10-25T12:44:55.933
1@FryAmTheEggman: It's correct, I meant the 'before' column. If more people have made this mistake, I will change my question to accept either. I admit I wasn't very clear. – marinus – 2014-10-27T06:08:19.357
@MartinBüttner: as long as you specify the order, it does not matter. – marinus – 2014-10-27T06:08:40.093