23
4
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 Y
is 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 X
is 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 Hello, World!
:
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
s
and a numbern >= 0
, output then
th string on the XOROR sequence with seeds
, withn = 0
being 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 seeds
. 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.
I'm having trouble parsing the sentence "So, whatever function I am about to define on a three-char string, Y will become." Could this be reworded: "Y will be the result of the function I'm about to define, a function on three-char strings."? – hYPotenuser – 2016-03-04T17:59:27.760
3
All of the
– mbomb007 – 2016-03-04T18:24:17.760o
s make it look like a zerg rush.@hYPotenuser Yes! I will do so. – Conor O'Brien – 2016-03-04T18:29:23.500
3Observation: Since XOR and OR preserve the number of bits and all ASCII is 7 bits, the only case when a CHARCODE is > 126 is if it is 127. Therefor, you can just replace it with a space (32) since
127%127+32==32
. – CAD97 – 2016-03-04T21:24:54.3932Why is
n=0
not the original string? – Neil – 2016-03-04T21:59:45.363@Neil I don't know. It was rather arbitrary. – Conor O'Brien – 2016-03-04T22:06:45.697
I think for
5
the output iso_<c c 4+ o
– Luis Mendo – 2016-03-05T00:56:58.867@CᴏɴᴏʀO'Bʀɪᴇɴ The example cases are broken from step 0. The final result of (d^!|NULL) should be (69 or E) not (101 or e). – FatalSleep – 2016-03-05T13:59:51.147
@CᴏɴᴏʀO'Bʀɪᴇɴ The charcode part is ambiguous. Do you do
(CHAR%127)+32
on(A^B)|C
or on eachindividual cellA
,B
andC
? – FatalSleep – 2016-03-05T14:35:44.4903@FatalSleep As for you first complaint, I stated that, if no cell is present, the result is a space, so it would rather be
(d^!)|(space)
. As for you second question, you perform(CHAR%127)+32
after the XOROR is performed. – Conor O'Brien – 2016-03-05T16:24:51.060Oh whoops! Thank you for the re-clarification. – FatalSleep – 2016-03-05T16:49:50.040
@FatalSleep It's truly my pleasure :) – Conor O'Brien – 2016-03-05T16:50:13.057
@StewieGriffin I'll pretend as if you didn't say your first reason, and move on to the second. "Better safe than sorry" is the main reason I protected it. (and I think you can edit comments.) – Conor O'Brien – 2016-03-06T21:54:03.180