Find the shortest mirror quine in a language of your choice.

A mirror quine is a quine whose source code is equal to the reverse of its own source code.


1) Length of source code should be atleast 2.

2) Quines not allowed are the one whose text can be echoed directly.

Example: Let L' be any language, then a quine with source code like ABBA or ABCBA is a mirror quine.

  • \$\begingroup\$ Maybe you also want to exclude the form code+comment char+reverse code. \$\endgroup\$
    – Howard
    Commented Oct 18, 2013 at 6:18
  • \$\begingroup\$ @Howard yes, thanks for pointing this out.. \$\endgroup\$
    – Coding man
    Commented Oct 18, 2013 at 6:32
  • \$\begingroup\$ does ( mirror as (, or as ) (and similarly for other brackets)? If it's the former, then I think it disqualifies any potential solution. Even golfscripters need blocks. \$\endgroup\$ Commented Oct 18, 2013 at 6:43
  • \$\begingroup\$ @Howard what you suggest? or lets wait for atleast a single possible solution :P \$\endgroup\$
    – Coding man
    Commented Oct 18, 2013 at 6:47
  • 2
    \$\begingroup\$ The name "mirror quine" is confusing. It sounds like a program that outputs the reverse of its source (itself an interesting challenge perhaps). Yours is a palindromic quine. \$\endgroup\$
    – Timwi
    Commented Dec 16, 2015 at 5:28

5 Answers 5


HQ9+, 3 Characters

Am I cheating?

  • 2
    \$\begingroup\$ The right tool for the task. \$\endgroup\$ Commented Oct 18, 2013 at 15:27
  • 1
    \$\begingroup\$ Finding an unexpected use for HQ9+ is always a good thing, so if it is a cheat, it's completely justified. \$\endgroup\$
    – breadbox
    Commented Oct 18, 2013 at 16:17

Perl, 53 characters

Perl's multifaceted text-handling features once again prove useful for golfing.




Ignore the BEGIN and END markers; they're just there to keep the blank lines at the beginning and end from being suppressed from display. Yes, the source really does have two blank lines at the top and one blank line at the bottom. This apparent lack of symmetry may throw you at first, but that's just the nature of line breaks. What's really happening, of course, is that the source both begins and ends with two line break characters.

  • 1
    \$\begingroup\$ wait, what? No parens? +1 from me \$\endgroup\$ Commented Oct 18, 2013 at 18:28
  • \$\begingroup\$ Why 2 line breaks at beginning and end? Why not 1? \$\endgroup\$
    – Cruncher
    Commented Dec 12, 2013 at 18:04
  • \$\begingroup\$ The concluding blank line closes the here-doc. \$\endgroup\$
    – breadbox
    Commented Dec 12, 2013 at 19:17

Golfscript, 33 characters

""~.{'""~.'print tnirp'.~""'}.~""

Since every language uses parentheses of some form, I assert the "( mirrors to (" version of this challenge is impossible (under rule #2), and assume ( mirrors to ). Additionally, this version provides more visual symmetry.

If trailing whitespace is allowed, empty strings can be replaced with newlines (29 characters):

n~.{'n~.'print tnirp'.~n'}.~n

Proceeds as follows:

  • ""~. pushes an empty string onto the stack, evaluates it and clones the input (empty string)
  • {...} is a block
  • .~"" clones the block, evaluates one copy and pushes an empty string to the stack.

That block:

  • '""~.' pushes the string ""~. onto the stack
  • print outputs it directly and removes it from the stack
  • tnirp is an undefined symbol and does nothing
  • '.~""' pushes the string .~"" onto the stack

After the program finishes, the stack contents are printed:

  • the empty string (twice)
  • the main block, including delimiters
  • the program suffix as a string
  • another empty string

Befunge 98 - 40 35 31 or 29 characters


Saved another 4 characters, for 31 total, and complied with specs.

Or, if the other code can just be filler (29):


Old Version


Saved 5 characters by using ' to fetch the length of the program

#r:0g,:a4*`3+jb+1r@  @r1+bj+3`*4a:,g0:r#

Just a variation on a normal quine, but made into a palindrome.

:0g get the character at a location (counter, 0)
,   print it
:   take the counter
a4* get 10 * 4 (40, length of program)
`   compare them (0 if counter is less or equal, 1 if greater)
3+  add 3
j   jump that amount (4 or 3)

if 4:
@   end program

if 3:
r   head the other way (to the left)
1+  increment counter
bj  jump 11 chars (to beginning r (reverse direction again))

Mouse-2002, 73 bytes

2 0&FOPEN (x.74<^2&F?' !'x.1+x:)36!'~'!63):x+1.x'!'? F&2^<75.x( NEPOF&0 2

Not the answer you're looking for? Browse other questions tagged or ask your own question.