Writing quines is hard. Why not have your computer write them for you!

Your program will take as input an interpreter (in a Turing complete language of your choosing) for a language X, and you will output a quine in language X.

Notes:

  • Language X is guaranteed to be Turing complete (you do not need to check this (it would be impossible to do so anyways)).
  • Due to some issues that jimmy23013 raised in the comments, I'll also guarantee that the language has a quine.
  • A quine for the purposes of this challenge is a program that outputs its own source code when given no input.
  • The interpreter might throw errors if the program it is running has errors, so be prepared! (A quine shouldn't throw errors.)

Here is an example algorithm you can use. I am only putting it here so people don't claim this challenge is impossible:

Go through every possible program, running them all in parallel or via Dovetailing. Throw out programs that cause errors. Whenever a program outputs its own source code, you are done. Since every Turing complete language has at least one quine, this is guaranteed to eventually return a result.

This is code golf, so the shortest answer wins!

closed as unclear what you're asking by tuskiomi, mbomb007, Post Left Garf Hunter, Zacharý, Timtech Aug 18 '17 at 19:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This seems like a fun one. But to be clear the program should take the interpreter as input? How on earth are we going to parse that?? – MD XF Jun 1 '17 at 3:55
  • 1
    It's possible to write quines in some languages that is not Turing complete. And someone can design a Turing complete language that a quine is impossible. – jimmy23013 Jun 1 '17 at 4:05
  • 3
    Go through every possible program, running them all - I'm not convinced this is possible in general. It is quite likely you'll get rm -rf / or shutdown -h now (or equivalents in the given language) before you get to a valid quine. Oh and there is also the thing with the halting problem - while(true) may well be generated before a quine. – Digital Trauma Jun 1 '17 at 6:16
  • 1
    "Since every Turing complete language has at least one quine, this is guaranteed to eventually return a result." There are some caveats to this. I can easily design a Turing-complete language that cannot output its own source code (consider a language whose source code is written entirely with letters, but which can only output 0s and 1s). Some TC languages don't have traditional output at all. The statement is only true if you define some encoding for arbitrary strings on whatever the language's output is. Then you can always find a program which produces output that encodes the source. – Martin Ender Jun 1 '17 at 6:41
  • 2
    However, you can't let people choose an arbitrary encoding, because then they could always choose a suitable encoding to trivialise the challenge. So I'd suggest guaranteeing that the language is capable of producing arbitrary strings as output to begin with, so that the source code can always be matched exactly. – Martin Ender Jun 1 '17 at 6:42