Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inspired by quine computing, this is a nondeterministic ouroboros program that produces a random program that in turn produces another random program. Currently, at most 2^64 unique programs could be produced, but since the JVM allows for up to 65535 characters (including most unicode characters) in valid class names this could easily be increased.
public class NondeterministicOuroboros_0 {
public static void main(String[] args) {
Long id = 0L;
char quote = 34;
String[] code = {
"public class NondeterministicOuroboros_0 {",
" public static void main(String[] args) {",
" Long id = 0L;",
" char quote = 34;",
" String[] code = {",
" };",
" String next = new Long(new java.util.Random().nextLong()).toString();",
" code[0] = code[0].replace(id.toString(), next.replace('-', 'N'));",
" code[2] = code[2].replace(id.toString(), next);",
" for(int i=0; i<5; i++){",
" System.out.println(code[i]);",
" }",
" for(int i=0; i<code.length; i++){",
" System.out.println(quote + code[i] + quote + ',');",
" }",
" for(int i=5; i<code.length; i++){",
" System.out.println(code[i]);",
" }",
" }",
"}",
};
String next = new Long(new java.util.Random().nextLong()).toString();
code[0] = code[0].replace(id.toString(), next.replace('-', 'N'));
code[2] = code[2].replace(id.toString(), next);
for(int i=0; i<5; i++){
System.out.println(code[i]);
}
for(int i=0; i<code.length; i++){
System.out.println(quote + code[i] + quote + ',');
}
for(int i=5; i<code.length; i++){
System.out.println(code[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment