The XOROR sequence
Mathematica, 133 bytes
FromCharacterCode@Nest[BlockMap[If[#>126,#~Mod~127+32,#]&[BitXor[#,#2]~BitOr~#3]&@@#&,ArrayPad[#,1,32],3,1]&,ToCharacterCode@#,#2+1]&
It would be nice to make a CellularAutomaton[]
solution work, but I kept coming up short. Anyone?
Edit: some pretty pictures (click to enlarge)
plotCA[str_, n_] := ArrayPlot[NestList[foo[str],n], ColorFunction -> "Rainbow"]
plotCA["Hello, World!", 60]
:
plotCA[bXORnotb, 100]
:
plotCA[raven, 100]
:
Java, 193 185 bytes
Because Java.
-8 bytes by switching to looping rather than recursing to make it an anonymous function
Returns the n'th iteration of XOROR on s.
(s,n)->{String o=s;for(;n-->=0;){o="";for(int i=0;i<s.length();i++){char c=(char)((i>1?s.charAt(i-1):' ')^s.charAt(i)|(i<s.length()-1?s.charAt(i+1):' '));o+=c>126?' ':c;}s=o;}return o;}
Readable version:
static BiFunction<String, Integer, String> f = (s,n)->{
String o=s;
for(;n-->=0;) {
o = "";
for (int i=0;i<s.length();i++) {
char c=(char)((i>1?s.charAt(i-1):' ')^s.charAt(i)|(i<s.length()-1?s.charAt(i+1):' '));
o+=c>126?' ':c;
}
s=o;
}
return o;
};
public static void main(String[]a) {
System.out.println(f.apply("Hello, World",1));
}
Pretty much a literal implementation of the spec, with a recursive loop to apply the operation n times. Some bytes were saved, however, with my observation that the CHARCODE>126 clause will only ever happen with CHARCODE==127, which results in saving SPACE
instead of DEL
.
I ran my code over a few arbitrarily chosen strings and found this wonderful cycle:
oook$ok$ok$ok$
ook$ok$ok$ok$o
oo$ok$ok$ok$ok
oook$ok$ok$ok$
CJam, 38 bytes
lri){2S*\*3ew{)\:^|_'~>{i127%' +}&}%}*
Test it here.
Explanation
l e# Read string.
ri e# Read n.
){ e# Run this block n+1 times...
2S*\* e# Wrap in two spaces.
3ew e# Get all (overlapping) substrings of length 3.
{ e# Map this block over all those substrings...
)\ e# Pull off the third character and put it below the other two.
:^ e# Take XOR of the other two.
| e# OR with the third one.
_'~> e# Duplicate and check if it's greater than '~'.
{i127%' +}& e# If so, mod 127, add to space.
}%
}*