Shortest Mirror Quine Challenge

7

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.

Coding man

Posted 2013-10-18T05:52:31.503

Reputation: 1 193

Question was closed 2016-07-03T10:10:03.177

2The 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. – Timwi – 2015-12-16T05:28:24.793

Maybe you also want to exclude the form code+comment char+reverse code. – Howard – 2013-10-18T06:18:19.860

@Howard yes, thanks for pointing this out.. – Coding man – 2013-10-18T06:32:40.930

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. – John Dvorak – 2013-10-18T06:43:51.183

@Howard what you suggest? or lets wait for atleast a single possible solution :P – Coding man – 2013-10-18T06:47:09.887

or lets wait for at least a single possible solution considering "(" mirrors as "(" (and similarly for other brackets) and also exclude the form code+comment char+reverse code – Coding man – 2013-10-18T06:55:42.667

@Codingman My Befunge program does exactly that – Justin – 2013-12-11T23:34:26.890

For anyone looking for the non-closed, clearly specified version of this challenge, it's here. Unfortunately, I can't re-close as duplicate without moderator intervention, and a comment works almost as well as getting the moderators would.

– None – 2017-06-02T15:09:19.550

Answers

14

HQ9+, 3 Characters

Am I cheating?

+Q+

alephalpha

Posted 2013-10-18T05:52:31.503

Reputation: 23 988

2The right tool for the task. – Johannes Kuhn – 2013-10-18T15:27:58.247

1Finding an unexpected use for HQ9+ is always a good thing, so if it is a cheat, it's completely justified. – breadbox – 2013-10-18T16:17:25.927

13

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.

breadbox

Posted 2013-10-18T05:52:31.503

Reputation: 6 893

1wait, what? No parens? +1 from me – John Dvorak – 2013-10-18T18:28:25.980

Why 2 line breaks at beginning and end? Why not 1? – Cruncher – 2013-12-12T18:04:55.503

The concluding blank line closes the here-doc. – breadbox – 2013-12-12T19:17:24.690

7

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

John Dvorak

Posted 2013-10-18T05:52:31.503

Reputation: 9 048

1

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))

Justin

Posted 2013-10-18T05:52:31.503

Reputation: 19 757

1

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

cat

Posted 2013-10-18T05:52:31.503

Reputation: 4 989