Cellular Automata are truly fascinating. The ones that are usually talked about are the binary ones, i.e., the ones representable by a number. However, those, in my opinion, have been done to death. Ternary CAs are more interesting, but we have all of ASCII to consider! What fun could that be!
Instead of deciding a ruleset for each character, I will use a simple deciding rule which I will talk about soon. To decide the next generation, we look at the three "top" cells, much like a cellular automata. Observe an example:
QWERTY X Y Z
The "top" of
WER, being the cells above-and-right, above, and above-and left. Y will be the result of the function I'm about to define, which is a function on three-char strings. The "top" of
QW, or a space filling in the non-existent/missing cell.
Now, for the
fun function! I call this sequence the XOROR sequence for a reason. Let
A be the top-left cell charcode,
B be the above cell charcode, and
C be the top-right cell charcode. Then, the resulting cell is the character whose charcode is
(A XOR B) OR C, that is,
(A^B)|C. (If a resulting value is greater than 126, then it is set to
(CHARCODE % 127) + 32. Nothing is done if a value is less than 32.) Here is an example of the seed
S: Hello, World! 0: mmmo/c_ z}~)e m = ( )^(H)|(e) = (32^72)|101 = 104|101 = 109 (m) m = (H)^(e)|(l) = (72^101)|108 = 45|108 = 109 (m) etc. 1: mmo/c_< +wl 2: mo/c_<c< + |; 3: o/c_<c ?+ g 4: oc_<c c??4+gg 5: 0_<c c 4+ o 6: _<c ccc4??ooo 7: c ccc4 ?o o 8: ccccc4w? pooo 9: cccc4w h o A: ccc4wc hh ooo B: cc4wc4kh ooo C: c4wc4 #ooo o D: wwc4w4#ooo oo E: wc4wwc oo oo F: w4wwc4oo oo o G: wwwc4 oo oo H: wwc4w4 oo oo I: w4wwc4oooo oo J: wwwc4 oo oo K: wwc4w4oo oo o L: wc4wwo oo oo M: w4wwo8ooo oo N: wwwo8 o oo o O: wwo8w8oooo oo
And we can proceed on for a while hereafter. This modification of the string is called the XOROR sequence.
Objective You are to write a program or function that does one of the following tasks:
- Given a string
sand a number
n >= 0, output the
nth string on the XOROR sequence with seed
n = 0being the first transformation of the string.
- Given a string
s, output (for programs) or generate (for functions/generators) an infinite stream of the XOROR sequence with seed
s. You may choose to stop if the sequence repeats, but this is not necessary.
s will always only consist of printable ASCII characters, from space to tilde plus tabs (no newlines.)
This is a code-golf, so the shortest program in bytes wins.