# Golf a mutual quine

Using two languages of your choice, write the smallest “mutual quine” you can.

That is, write a program P in language A that outputs the source code for a program Q in language B, such that the output of program Q is identical to the source code for P.

Empty files don't count, nor do "read the source file and print it"-style programs.

Edit: Answers with P=Q no longer count.

• Btw, this should preclude cases where the sources match. For example 1 is a quine in several languages. So you could say its a J program that prints a Golfscript program that prints a...... and so on. Commented May 16, 2011 at 20:49
• you can adopt the rule of "Try to avoid or rather don't use 1 byte submissions like this one ,since it spoils all fun." from codegolf.stackexchange.com/questions/1393/… Commented May 16, 2011 at 22:40
• A Brainfuck + Befunge solution should be posted. Commented Jul 15, 2011 at 0:13
• Can language A = language B?
– user58826
Commented May 22, 2017 at 19:01
• Since this is golf, can you clarify the scoring criteria? For example, is the final score the sum of the byte counts of P and Q? Or the minimum of the byte counts of P and Q? Commented Mar 29, 2018 at 20:06

## Python and Ruby, 39 characters

This Python snippet

s='puts %%q{s=%r;print s%%s}';print s%s


generates this Ruby snippet

puts %q{s='puts %%q{s=%r;print s%%s}';print s%s}


which then generates the inital Python snippet again:

# C and C++, 123 chars

This C (compilable with gcc v4.3.4):

#include <stdio.h>
main(){char *c="#include <stdio.h>%cmain(){char *c=%c%s%c;printf(c,10,34,c,34);}";printf(c,10,34,c,34);}


outputs this (identical) C++ (compilable with g++ 4.3.4, one warning):

#include <stdio.h>
main(){char *c="#include <stdio.h>%cmain(){char *c=%c%s%c;printf(c,10,34,c,34);}";printf(c,10,34,c,34);}


This is within the rules as posted. :P And, like Ventero's, this is based on J B's answer.

• OK, so it was within the rules as posted until the edit saying the sources can't be the same. A minor change could fix that, but I'm disinclined to encourage such late edits. Commented Jun 8, 2011 at 21:22

# ><> (Fish) and Python - 26 characters

"00gr00g:a9*2+$' tnirp'>o<  Generates this Python print "\"00gr00g:a9*2+$' tnirp'>o<"

• You have an issue with the ><> code because " and ' enable string parsing, so the entire program is just pushed onto the stack and never displayed. Commented May 16, 2011 at 22:44
• @Bass5098 That's precisely how the whole thing works. The first " enables string parsing. It reads.the whole program and then wraps back around to.the first " and runs the program with itself on the stack Commented May 17, 2011 at 10:22
• Fixed the issue in my interpreter. Your ><> code outputs print \00gr00g:a9*2+$' tnirp'>o< after timing out. I'm pretty sure this is because g copies the actual cell contents, but o outputs the ASCII version of the character, and " isnt a valid ASCII character code. ideone.com/kaM0r Commented May 17, 2011 at 22:38 • @Bass5098 " is ASCII 34. Your interpreter must be off. Commented May 18, 2011 at 0:11 Python + Piet one-liners: 417 chars + 7391 7107 executing codels This Python script produces a 7393 x 2 image; the rightmost 2x2 block of which is a "sentinel" which terminates the program; so I'm not counting those; and the second row is otherwise white. I can probably golf the piet code down further by using addition/subtraction/multiplication chains instead of the naive binary algorithm... but I don't want to give away a solution to a future puzzle. I'm not going to post the image here, because of its ridiculous dimensions. If you want to see it, run the python code, and pipe the output to a .ppm file. Then, convert the .ppm to a .gif, and run the output at Rapapaing. (alternately, use a non-web Piet interpreter that groks .ppm) A='P=lambda A:reduce(lambda(D,H,B),P:(D[P/3:]+D[:P/3],H[P%3*2:]+H[:P%3*2],B+"".join("%i "%H[(D[0]/P)%2]for P in[1,2,4])),map(" A ! @ B".find,A),([1,3,2,6,4,5],[0,192,192,255,0,255],"P3 %i 2 255 "%(len(A)+2)))[2]+"255 "*4+"0 0 "+"255 "*len(A)*3+"255 0 0 "*2;B=lambda D:["@!%s","@@!%s!"][D%2]%B(D/2)if 1<D else"";print P("".join("A%sB"%B(ord(D))for D in"A=%s;exec A[:-13]"%A)+" ");exec A[:-13]';exec A[:-13]  edit: golfed the piet a bit by reducing Hamming weight of variable names. less golfed pre-quine: This is a previous version, before I realized I could make it a one-liner. It's marginally easier to understand. The function P translates a special instruction set into Piet; and the function p takes an integer and produces a sequence of instructions to create that integer on the stack. I'm only using the instructions =,+,:,|, so this could probably be made more efficient... but I kinda like having a fullblown Piet compiler (of sorts) in the source. s="""def P(s): l=len(s)+1;R="P3 %i 2 255 "%(l+2);C=[1,3,2,6,4,5];V=[0,192,192,255,0,255] for x in map("=|^+-*/%~>.,:@$?#!".find,"="+s):
C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2]
for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2]
return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2
p=lambda x:[":+%s","::+%s+"][x%2]%p(x/2)if x/2 else""
print P("".join("|%s!"%k(ord(c))for c in "s="+s+";exec s[:-13]"))
exec s[:-13]"""
exec s[:-13]

• Piet Creator is a much nicer (and far less buggy) Piet IDE. Written by a user of this site, by the way :)
– Joey
Commented Jul 17, 2011 at 22:02
• I've used Piet Creator before; it's a great tool. Rapapaing is nice for people who are lazy, like me, and don't want to bother. FWIW, I'd use Piet Creator if you ran it through github.com/kripken/emscripten/wiki, and put that up on your page. Commented Jul 17, 2011 at 23:52
• I couldn't even get the Qt version to compile here ;)
– Joey
Commented Jul 18, 2011 at 7:33
• ;) Thanks for trying, anyway. I wrote you a fuzz tester: codegolf.stackexchange.com/questions/2922/… Commented Jul 20, 2011 at 21:38
• Well, you could poke Casey in chat and point him to it ;-)
– Joey
Commented Jul 20, 2011 at 21:40

# Java to Python - 219

Java:

class Q{public static void main(String[]a){char q=34,c=39;String s="print%sclass Q{public static void main(String[]a){char q=34,c=39;String s=%s%s%s;System.out.printf(s,c,q,s,q,c);}}%s";System.out.printf(s,c,q,s,q,c);}}


Python:

print'class Q{public static void main(String[]a){char q=34,c=39;String s="print%sclass Q{public static void main(String[]a){char q=34,c=39;String s=%s%s%s;System.out.printf(s,c,q,s,q,c);}}%s";System.out.printf(s,c,q,s,q,c);}}'


Makes use of the fact that python allows ' for strings; this makes it much easier to write the java program's source in the python program.

• +1 for doing the dirty work in the worst golfing language ever. :P Commented Mar 10, 2014 at 21:09

# /Brainf..k/, 6988 bytes

## Brainfuck

++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++>>>+>>>++++++++++>>>+++++++++++>>>++>>>+++++++++>>>+>>>++>>>++++++>>>+>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>++>>>+++++++>>>++>>>++++++++++>>>+>>>++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++++>>>+++++++++++>>>+>>>++>>>+>>>++>>>++>>>+++++++>>>++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>+>>>++++++>>>+++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++>>>++++++>>>+++++++>>>+>>>+>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>+>>>+>>>+>>>+>>>++++++++++>>>+++++++++++>>>++>>>+>>>+>>>+>>>+>>>++>>>+>>>++>>>+>>>++>>>++>>>++>>>++++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++>>>++++++++++>>>+++++++++++>>>+>>>++>>>++>>>++>>>++>>>++++++>>>+++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++++>>>+++++++++>>>++>>>++++++++++>>>+>>>+>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++>>>++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>++++++>>>+++++++>>>+++++++>>>++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>++++++>>>++++++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++++>>>+>>>++>>>+++++++++>>>++++++>>>++++++>>>+++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++++++>>>++++++>>>+++++++>>>+>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>+>>>++++++>>>+++++++>>>++>>>++++++++++>>>++++++>>>++++++>>>++++++>>>++++++++>>>++++++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++>>>++++++++>>>+++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++>>>++++++>>>++++++++>>>++++>>>+++++++>>>+++++>>>+++>>>+++++>>>++++>>>+++++++>>>+++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++>>>+++++>>>++++++++>>>++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++++>>>++++++>>>++++++++>>>++++++>>>++++++>>>++++++>>>+++++++++>>>+++++++>>>+++++++>>>+++++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++>>>+++++++>>>++++>>>++++++++>>>++++++>>>+++>>>+++>>>+++++++>>>++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>+++++++++>>>++++++>>>+++++>>>+++++++>>>+++++++>>>+++++++>>>+++++++>>>+++++++++>>>+++++++++++>>>++++++++++>>>+++++++++++>>>++++++>>>+++++++>>>{({}<>)<>}<>{([({})]()<((((()()()()()){}){}){})>){({}()<({}())>){({}()<({}()())>){({}()<({}()())>){({}()<({}())>){({}()<({}((()()()){}()){})>){({}()<({}()())>){({}()<({}(((()()()){}()){}){}())>){({}()<({}()())>){({}()<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}}}}{}({}<(<>)<>{({}<>)<>}{}>)(<><>)<>{({}<>)<>}{}<>{({}[()])<>(((((()()()){}())){}{}){}())<>}{}<>(((({})(((()()())){}{}){}())))<>}{}([]){((({}[()])<{({}[()]<({}<({}<>)<>>)>)}{}>)<{({}[()]<<>({}<>)>)}{}>)}{}{<>({}<>)}{}(<>){<<<[<<<]>>>[>++++++++++++++++++++++++++++++++++++++++.<[->.+.->+<<]>+.[-]>>]<[<<<]>>>[<++++++++++++++++++++++++++++++++++++++++>-[<+>-[<++>-[<++>-[<+>-[<++++++++++++++>-[<++>-[<+++++++++++++++++++++++++++++>-[<++>-[<++++++++++++++++++++++++++++++>-[<++>-]]]]]]]]]]<.>>>>]}{}<>


Try it online!

## Brain-Flak

(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()())(())(()())(()()()()()())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()())(())(()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(())(()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(())(()()()()()())(()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()())(()()()()()())(()()()()()()())(())(())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(())(())(())(())(()()()()()()()()()())(()()()()()()()()()()())(()())(())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()())(()()()()()()()()()())(()()()()()()()()()()())(())(()())(()())(()())(()())(()()()()()())(()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()()()())(()()()()()()()()())(()())(()()()()()()()()()())(())(())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()())(()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()())(()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(()()()()()())(()()()()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()())(())(()())(()()()()()()()()())(()()()()()())(()()()()()())(()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()())(()()()()()()())(())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()())(()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(())(()()()()()())(()()()()()()())(()())(()()()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()())(()()()()()())(()()()()()()()())(()()()())(()()()()()()())(()()()()())(()()())(()()()()())(()()()())(()()()()()()())(()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()())(()()()()())(()()()()()()()())(()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()()())(()()()()()())(()()()()()()()())(()()()()()())(()()()()()())(()()()()()())(()()()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()())(()()()()()())(()()())(()()())(()()()()()()())(()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()()()()())(()()()()()())(()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()())(()()()()()()()()())(()()()()()()()()()()())(()()()()()()()()()())(()()()()()()()()()()())(()()()()()())(()()()()()()()){({}<>)<>}<>{([({})]()<((((()()()()()){}){}){})>){({}()<({}())>){({}()<({}()())>){({}()<({}()())>){({}()<({}())>){({}()<({}((()()()){}()){})>){({}()<({}()())>){({}()<({}(((()()()){}()){}){}())>){({}()<({}()())>){({}()<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}}}}{}({}<(<>)<>{({}<>)<>}{}>)(<><>)<>{({}<>)<>}{}<>{({}[()])<>(((((()()()){}())){}{}){}())<>}{}<>(((({})(((()()())){}{}){}())))<>}{}([]){((({}[()])<{({}[()]<({}<({}<>)<>>)>)}{}>)<{({}[()]<<>({}<>)>)}{}>)}{}{<>({}<>)}{}(<>){<<<[<<<]>>>[>++++++++++++++++++++++++++++++++++++++++.<[->.+.->+<<]>+.[-]>>]<[<<<]>>>[<++++++++++++++++++++++++++++++++++++++++>-[<+>-[<++>-[<++>-[<+>-[<++++++++++++++>-[<++>-[<+++++++++++++++++++++++++++++>-[<++>-[<++++++++++++++++++++++++++++++>-[<++>-]]]]]]]]]]<.>>>>]}{}<>


Try it online!

The Brain-Flak might time out on TIO.

## Explanation

Coming soon.

• That polyglot at the end is quite impressive... Commented May 22, 2017 at 20:21
• Explanation coming soon -> Jan 27 Commented Sep 22, 2017 at 16:22
• @MDXF Explanation coming soon checks date Commented Aug 11, 2020 at 0:09
• When you'll add an explanation? Commented Dec 16, 2022 at 19:55
• @Fmbalbuena Soon. Commented Dec 17, 2022 at 4:04

## Ruby and Python (393 + 413 = 806 chars)

Slight change of this answer of mine. Could definitely be reduced since I just hard-coded the input without any optimisation.

### Ruby (393 chars)

require 'json';s=%q[{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}];j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))


### Python (413 chars)

import json,re;s='''{"ruby":[" %q[","require 'json';s=##;j=JSON.load s;puts j[l='python'][1].sub('##',j[l][0].delete(' ')+s+j[l][2].delete(' '))"," ]"],"python":["' ''","import json,re;s=##;j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))","' ''"]}''';j=json.loads(s);l='ruby';print(re.sub('##',j[l][0].replace(' ','')+s+j[l][2].replace(' ',''),j[l][1],1))


# Gol><> and APL, 10 bytes and 13 bytes

'r3d*:::}H


Try it online! Which outputs:

'''r3d*:::}H'


Try APL online!

Which simple prints the code as a string (with the ' escaped with another ')

# Python 2 to Befunge 98, 94 78

Again, making use of Python's two ways of making strings:

Python:

s='<@,kM%c%cs=%c%s%c;print s%%(39,34,39,s,39,34)%c';print s%(39,34,39,s,39,34)


Befunge 98:

<@,kM'"s='<@,kM%c%cs=%c%s%c;print s%%(39,34,39,s,39,34)%c';print s%(39,34,39,s,39,34)"


The python program formats the string to include itself and the characters for the single and double quote.

The Befunge program works like this:

• <: move to the left, and wrap around. So now we execute the commands from right to left
• ": make it so that every char we encounter is pushed to the stack until we encounter another ", so we push:

)43,93,s,93,43,93(%s tnirp;'c%)43,93,s,93,43,93(%%s tnirp;c%s%c%=sc%c%Mk,@<'=s


Which is actually just the python program, reversed because of the way Befunge prints (which is a pop+print loop)

• 'M: push M to the stack. M is also the number 77, which is one less than the number of chars pushed to the stack by the "s.
• k: pop the top value off the stack (M) and do the next operation that many times, plus one.
• ,: pop the top value off the stack and print the char.
• @: end the program.
• Good grief, and in a notoriously difficult esoteric language too. Thats..... terrifying. Commented Oct 17, 2017 at 5:24

## Clipper and C (111 + 108 = 219 chars)

### Clipper (111)

?'char*f="%c%cchar*f=%c%s%c;main(){printf(f,63,39,34,f,34,39,10);}%c%c";main(){printf(f,63,39,34,f,34,39,10);}'


### C (108)

char*f="%c%cchar*f=%c%s%c;main(){printf(f,63,39,34,f,34,39,10);}%c%c";main(){printf(f,63,39,34,f,34,39,10);}


This is a bit of a cop-out because:

1. the "print" command in Clipper is really simple: ?'foo' :-)
2. I based it on the "classic C" quine from http://www.nyx.net/~gthompso/quine.htm, with some modification to squeeze in the ? and 's.
3. I didn't #include <stdio.h>, so it gives a compiler warning
4. The C code output by the Clipper version had to be prodded to remove a line break that had been introduced by an 80-character column limit in either my terminal or the Harbour printing routine or something.
• Well, the BASIC PRINT command could be abbreviated ? as well :-)
– Joey
Commented Jul 20, 2011 at 21:41

# Jelly, 13 bytes

“Ṿ;⁾v+/ŒṘ”v


Try it online!

'“Ṿ;⁾v+/ŒṘ”v'


Try it online!

A Jelly quine that wraps itself in single quotes, such that the resultant RAD program simply prints the original Jelly program back out.

(a(:^)*a(S)*S):^


((a(:^)*a(S)*S):^)S


# Vyxal, 10 bytes

:qpq:qpq


Try it Online!

# VyxalV

\:qpq\:qpq


Try it Online!

The V flag does nothing, the first is a quine that unevaluates itself, and the second is a string.

Or...

# VyxalDrV, 16 bytes

q\:Ė\p1→ip:Ė


Try it Online!

# VyxalDr

0q\:Ė\p1→ip:Ė


Try it Online!

The 0 at the start is a NOP - Vyxal pads the stack with 0s anyway, so the two programs are functionally identical.

q\:Ė\p    :Ė # Standard eval quine
1→ip    # If V (single-char variable names) is off, this stores 1 to the variable ip.
# If it's on, this stores 1 to the variable i and prepends a 0 to the current program.


# Guile, 114 bytes

((lambda(v)(format #t".\\~s"(format #f" (~a~s)"v v)))"(lambda(v)(format #t\".\\\\~s\"(format #f\" (~a~s)\"v v)))")


Try it online!

# Forth (gforth), 139 bytes

.\" ((lambda(v)(format #t\".\\\\~s\"(format #f\" (~a~s)\"v v)))\"(lambda(v)(format #t\\\".\\\\\\\\~s\\\"(format #f\\\" (~a~s)\\\"v v)))\")"


Try it online!

# Python and ~-~! - 77 and 81 = 158

This Python code:

q=chr(124);s='@%sq=chr(124);s=%s;print(s%%repr(s))%s:';print(s%(q,repr(s),q))


outputs this ~-~! code:

@|q=chr(124);s='@%sq=chr(124);s=%s;print(s%%repr(s))%s:';print(s%(q,repr(s),q))|:


Can definitely be improved a lot, and adopts a whole bunch from the other answers.

# Javascript and Windows .bat, 71 bytes and 81 bytes

f=()=>{console.log('echo f='+(f+';f()').replace(/(?=[>^\\])/g,'^'))};f()


and

echo f=()=^>{console.log('echo f='+(f+';f()').replace(/(?=[^>^^^\^\])/g,'^^'))};f()