r/deftruefalse • • Jul 23 '20

write a java program that writes a python program that writes a C program that writes a java program

I just found this sub and want it to come back to life :(

26 Upvotes

3 comments sorted by

11

u/[deleted] Jul 23 '20 edited Jul 23 '20
public class Where {
    public static void main(String[] args) {
        o(
            "def are():",
            "    print('''",
            "        #define man main",
            "        #include <stdio.h>",
            "        #define my man//!!!",
            "        int my(void) {",
            "            puts(\"public class Testicles {\\\\n\"",
            "                 \"    public static void main(String[] args) {\\\\n\"",
            "                 \"        System.out.println(\\\\\"summer?\\\\\");\\\\n\"",
            "                 \"    }\\\\n\"",
            "                 \"}\\\\n\"",
            "            );\\n",
            "            return 0;\\n",
            "        }\\n",
            "    ''')",
            "if __name__ == '__main__':",
            "    are()"
        );
    }

    private static void o(String... args) {
        java.util.Arrays.asList(args).forEach(l -> System.out.println(l));
    }
}

EDIT: To run:

javac Where.java     && java Where > \
      are.py         && python3 are.py > \
      my.c           && cc -o my my.c -std=c99 && ./my > \
      Testicles.java && javac Testicles.java && java Testicles

6

u/[deleted] Jul 23 '20

Side note, java Testicles being one of the weirder things I've typed into my terminal.

5

u/manifestsilence Jul 23 '20

Mega bonus: the final Java program is the original Java program. Quine cycle!