CBOT Quine
#1839
Replies: 1 comment
-
string Replace(string s, string from, string to) {
string result = "";
for(int i = 0; i < strlen(s); ++i) {
if(strmid(s, i, 1) == from) {
result += to;
} else {
result += strmid(s, i, 1);
}
}
return result;
}
extern void CBOTQuine() {
string s = "string Replace(string s, string from, string to) {\n string result = \"\";\n for(int i = 0; i < strlen(s); ++i) {\n if(strmid(s, i, 1) == from) {\n result += to;\n } else {\n result += strmid(s, i, 1);\n }\n }\n return result;\n}\n\nextern void CBOTQuine() {\n string s = \"#\";\n file f(\"CBOTQuine.cbot\", \"w\");\n f.writeln(Replace(s, \"\\43\", Replace(Replace(Replace(s, \"\\\\\", \"\\\\\\\\\"), \"\\\"\", \"\\\\\\\"\"), \"\\n\", \"\\\\n\")));\n f.close();\n}\n";
file f("CBOTQuine.cbot", "w");
f.writeln(Replace(s, "\43", Replace(Replace(Replace(s, "\\", "\\\\"), "\"", "\\\""), "\n", "\\n")));
f.close();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions