7
\$\begingroup\$

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.

Note:

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.

\$\endgroup\$

closed as unclear what you're asking by Mego, NoOneIsHere, Rɪᴋᴇʀ, pajonk, Blue Jul 3 '16 at 10:10

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.

  • \$\begingroup\$ Maybe you also want to exclude the form code+comment char+reverse code. \$\endgroup\$ – Howard Oct 18 '13 at 6:18
  • \$\begingroup\$ @Howard yes, thanks for pointing this out.. \$\endgroup\$ – Coding man Oct 18 '13 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\$ – John Dvorak Oct 18 '13 at 6:43
  • \$\begingroup\$ @Howard what you suggest? or lets wait for atleast a single possible solution :P \$\endgroup\$ – Coding man Oct 18 '13 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 Dec 16 '15 at 5:28
14
\$\begingroup\$

HQ9+, 3 Characters

Am I cheating?

+Q+
\$\endgroup\$
  • 2
    \$\begingroup\$ The right tool for the task. \$\endgroup\$ – Johannes Kuhn Oct 18 '13 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 Oct 18 '13 at 16:17
13
\$\begingroup\$

Perl, 53 characters

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

---BEGIN---


say$/.reverse$_=<<'';say
yas;''<<=_$esrever./$yas

----END----

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.

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

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
\$\endgroup\$
1
\$\begingroup\$

Befunge 98 - 40 35 31 or 29 characters

#r:0g,:a3*`!e*j@j*e!`*3a:,g0:r#

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

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

>:0g,:e2*`!e*j@j*e!`*2e:,g0:>

Old Version

#r:0g,:'#`3+ja+1r@r1+aj+3`#':,g0:r#

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))
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$

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