Last active
January 26, 2016 23:21
-
-
Save benjholla/a1ce13599bfe68b4c2dc to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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