Print your code backwards - reverse quine

85

19

Write a program that prints its own source code out backwards, in other words an eniuq.

Scoring:

  • +50 if you use pull data from the Internet.
  • +25 if you read your own source code.
  • +1 point per character
  • Lowest score wins.

Rules:

  • No using other files (e.g. reverse.txt)
  • Minimum code length is two characters.
  • Your program cannot be a palindrome.

ike

Posted 2013-12-18T15:47:30.867

Reputation: 1 753

1@lebatsnok You could move your comment to an answer now. :) – mbomb007 – 2016-04-22T16:07:24.667

1

Looks like this has been done before, just without the "no palindromes" rule.

– Iszi – 2013-12-18T18:59:10.790

3Are those scores bonuses or penalties? You need to specify in words if something is a penalty or a bonus, because saying +10 can be taken to mean either "score as if it had 10 more characters than it actually does" or "the code can have 10 more characters that won't be scored", or other interpretations. – AJMansfield – 2013-12-18T20:24:38.623

7@AJMansfield Lowest score wins means that +x would be a penalty, -x would be a bonus. – Iszi – 2013-12-18T20:32:53.883

1They are penalties. – ike – 2013-12-18T20:33:11.117

9The one question I have, then, is why is pulling data from the internet given a larger penalty than reading the source file? – AJMansfield – 2013-12-18T20:35:36.700

4Woohoo, 1st place on the hot network questions list :D Our site needs more attention... – Doorknob – 2013-12-19T00:09:20.583

Next time this needs an extra rule about syntax errors (or possibly standard error). – l0b0 – 2013-12-19T09:24:53.610

@DoorknobofSnow There's good attention and bad attention. I don't think it's a coincidence that the quality of new questions just dropped considerably (and it wasn't that high to begin with). – Gareth – 2013-12-19T12:17:37.377

I posted the challenge http://codegolf.stackexchange.com/questions/16043/mirror-quine-or-my-head-hurts which has tighter rules than this one, so every answer there would qualify as an answer here, but would not score as well. My current answer there is over 6000 characters.

– hildred – 2013-12-19T02:13:28.690

When are you actually going to accept a solution? – ProgramFOX – 2013-12-22T17:57:33.350

I can't post an answer but can add a comment. Here's a solution in R. reverse <- function() cat(paste(rev(strsplit(paste(deparse(get(as.character(match.call()[[1]]))), collapse="\n"),"")[[1]]), collapse="")). reverse() will print out ))"" = espalloc ,)]]1[[)"" ,)"n\" = espalloc ,)))]]1[[)(llac.hctam(retcarahc.sa(teg(esraped(etsap(tilpsrts(ver(etsap(tac { )( noitcnuf :P – lebatsnok – 2013-12-30T23:53:13.347

Answers

70

GolfScript - 2


1

(ie \n1 where \n is the newline character)

Output:

1

(ie 1\n)


To quote Ilmari:

GolfScript automatically appends a newline to the end of the output

Thus a newline followed by a number will print the number followed by a newline.

Justin

Posted 2013-12-18T15:47:30.867

Reputation: 19 757

26Pretty boring solution... – theonlygusti – 2015-04-13T17:26:55.867

14+1 I didn't think anything could beat the Mathematica solution. – Kaya – 2013-12-21T19:55:54.983

1@theonlygusti It's golfscript, whaddya expect... – Redwolf Programs – 2019-02-27T14:39:06.457

96

huh?, 5 characters

!hcuO

I actually have NO idea how it works, but If you download the interpreter, and if you write !hcuO, then you get Ouch!

To run this, you need to execute the program like this:

huh.exe !hcuO

It will actually look for a file called !hcuO, but it doesn't exist, so it outputs Ouch!

ProgramFOX

Posted 2013-12-18T15:47:30.867

Reputation: 8 017

93+1 for writing something you don't understand – Cruncher – 2013-12-18T17:54:19.270

30Is it not just a little ironic that you don't understand how your own code works, in an esolang that by design isn't supposed to understand your code either? – Iszi – 2013-12-18T18:08:18.610

@Iszi That's the joke. – AJMansfield – 2013-12-18T20:17:46.767

9I'm not sure you're using huh? right, though I'm having a hard time finding proper documentation. It seems the usage is intended to be huh.exe <path to source code> and Ouch! is returned for an invalid path. Try putting your code into an actual file, and feeding that file as an argument to huh? and see what happens. It's also interesting to see that it generates a Notes.txt file with some commentary. – Iszi – 2013-12-18T21:59:53.957

8Ok, this thing just told me it thinks it understands but I didn't see anything happen. Maybe I should stop toying with it on my primary system. – Iszi – 2013-12-18T22:04:16.003

What if there IS a file name !hcuO? – MilkyWay90 – 2019-05-15T22:51:39.370

85

Mathematica, 3 chars

a 2

a 2 means a times 2. So the answer is 2 a.

alephalpha

Posted 2013-12-18T15:47:30.867

Reputation: 23 988

2This will probably win unless someone can get a two char solution. – ike – 2013-12-20T01:54:45.193

22In fact I know a two char solution. Also in Mathematica: 1#. The output is #1. – alephalpha – 2013-12-20T11:24:39.827

7@alephalpha: Then you should post that as an answer! – ProgramFOX – 2013-12-20T12:07:21.973

65

H9+, 13 characters

!dlrow ,olleH

As the web page says, all characters that are not H, 9 or + are ignored, so my program will print Hello, world!

ProgramFOX

Posted 2013-12-18T15:47:30.867

Reputation: 8 017

1That's pretty darned clever! – theonlygusti – 2015-04-13T17:28:23.873

30The one and only practical benefit of crazy esoteric languages is to answer these crazy questions. – totymedli – 2013-12-19T08:11:30.487

It'd be more practical if these questions were so. – kojiro – 2013-12-22T18:50:31.197

41

Javascript: 34 characters

reifitnedi detcepxenU :rorrExatnyS

outputs SyntaxError: Unexpected identifier, at least in the Chrome console

scrblnrd3

Posted 2013-12-18T15:47:30.867

Reputation: 1 554

8Clever use of abusing the system through error abuse – WallyWest – 2013-12-19T01:46:12.097

2You sir, have made my day :D – major-mann – 2013-12-19T09:54:17.760

4

Not an original idea, there already was an answer about this in python 2.

– o0'. – 2013-12-19T13:53:49.220

1@Lohoris Sorry, I didn't see that one – scrblnrd3 – 2013-12-20T14:58:59.997

1Firebug console in Mozilla Firefox: tnemetats erofeb ; gnissim :rorrExatnyS => SyntaxError: missing ; before statement. – kenorb – 2014-07-21T13:09:42.643

27

Python, 43 41

_=']0~::[_%%_ tnirp;%r=_';print _%_[::~0]

shane

Posted 2013-12-18T15:47:30.867

Reputation: 541

24

Mathematica, 2 bytes

1#

Outputs:

#1

Jay Bosamiya

Posted 2013-12-18T15:47:30.867

Reputation: 371

20

TI-BASIC, 2

i2

Where i is the imaginary number.

Outputs 2i

Timtech

Posted 2013-12-18T15:47:30.867

Reputation: 12 038

8@kernigh Did you try it? It works fine. (If the last statement of a TI-BASIC program evaluates as an expression, its result is printed instead of 'Done' when the program terminates) – AJMansfield – 2015-04-13T18:04:53.533

1This only works in the home screen, not inside a PRGM. – kernigh – 2014-06-28T03:27:42.217

18

BASIC, 22 12 7 characters

:-)

1 enil ni rorre xatnyS

EDIT: If you're allowed to enter the program in immediate mode, then this could be reduced to rorre xatnyS (12 characters).

In BBC BASIC, you only need 7 characters:

ekatsiM

r3mainer

Posted 2013-12-18T15:47:30.867

Reputation: 19 135

13

ksh (21 chars)

$ dnuof ton :found :hsk
ksh: dnuof: not found

bash (31 chars)

$ dnuof ton dnammoc :found :hsab-
-bash: dnuof: command not found

sh (29 chars)

$ dnuof ton dnammoc :found :hs-
sh: dnuof: command not found

This one could not work on some Linux distributions, but works on OSX.


tcsh (26 chars)

$ .dnuof ton dnammoC :found.
.dnuof: Command not found.

csh (26 chars)

% .dnuof ton dnammoC :found.
.dnuof: Command not found.

Above should work on all *unix based OS.


Assumptions:

  • You don't have dnuof command or alias present.

bash (2-4 chars)

This one most likely doesn't qualify, but I'll share it as curiosity.

Assuming the previous shell command in Bash was $!. The following command:

!$

will produce: $!.

kenorb

Posted 2013-12-18T15:47:30.867

Reputation: 398

32Doesn't work for me, i have a command named dnuof – Kroltan – 2013-12-19T14:23:51.573

8I forgot to add, it doesn't work on distributions which has dnuof installed (whatever it is). Damn hackers. – kenorb – 2013-12-19T15:40:13.890

6Hahaha, there's a command named dnuof? :D what does it do? – Doorknob – 2013-12-19T23:51:50.203

From the name I can tell dnuof = (d)aily (n)ew (u)ser (of). This outputs how many users have been created on this computer today. Its arguments filter which computer(s) on the Internet to show for the daily new users. (The computer names are decoded by the program; each computer is given a different name.) (.dnuof is an alias for dnuof.) – None – 2019-11-08T06:57:13.350

13

C++ 472 characters

A lot of characters but I cant think of a simpler way in a c-based language.

#include<iostream>
#include<string.h>
#define p(t) std::cout<<'}'<<';'<<')'<<strrev(&std::string(#t)[0])<<t;
char* strrev(char*p){char*t=p;char*q=p;while(q&&*q)++q;for(--q;p<q;++p,--q)*p=*p^*q,*q=*p^*q,*p=*p^*q;return t;}
int main(){p("(p{)(niam tni};t nruter;q*^p*=p*,q*^p*=q*,q*^p*=p*)q--,p++;q<p;q--(rof;q++)q*&&q(elihw;p=q*rahc;p=t*rahc{)p*rahc(verrts *rahc;t<<)]0[)t#(gnirts::dts&(verrts<<')'<<';'<<'}'<<tuoc::dts )t(p enifed#>h.gnirts<edulcni#>maertsoi<edulcni#");}

user11232

Posted 2013-12-18T15:47:30.867

Reputation: 231

11

GolfScript, 12 chars

"-1%.`"-1%.`

This code takes the double-quoted string "-1%.`", reverses it (-1%), duplicates it (.) and un-evals (`) the second copy, restoring the double quotes around it.

Previous entry (13 chars):

{`'.~'+-1%}.~

Based on the 8-char quine {'.~'}.~ from this answer; the extra 5 chars are needed to stringify and reverse the output.

Ps. Note that GolfScript automatically appends a newline to the end of the output. If this is counted as part of the output, a corresponding newline can be prepended to either version of the code without affecting the output, for a cost of one extra char.

Ilmari Karonen

Posted 2013-12-18T15:47:30.867

Reputation: 19 513

10

Befunge 98 - 10 chars

"8k,'!1+,@

This works if your interpreter does not interpret wrapped lines after " as adding an extra space. If your interpreter does interpret wrapped lines like that, then this 11 char solution works (because duplicate spaces in a string literal are interpreted as one):

"9k,'!1+,@ 

If I can use g without penalty, then these also work (7 and 8 chars respectively):

"5k,g,@

and

"6k,g,@ 

Justin

Posted 2013-12-18T15:47:30.867

Reputation: 19 757

9

Ruby, 60

puts(2,s=<<2.chop.reverse,s)
puts(2,s=<<2.chop.reverse,s)
2

Based on a classic Ruby quine.

histocrat

Posted 2013-12-18T15:47:30.867

Reputation: 20 600

Nice use of heredocs. – Jon Purdy – 2013-12-23T19:25:33.457

9

Perl, 41

$_=q{print~~reverse"\$_=q{$_};eval"};eval

Old 52 character answer (27+25 penalty)

open+0;print ~~ reverse <0>

Reads its own source, stores the reverse in a scalar, and prints that.

smcg

Posted 2013-12-18T15:47:30.867

Reputation: 223

1The scalar operator can be replaced by ~~. However, you need to add +25 to your score for reading your own source code. – breadbox – 2013-12-18T19:26:58.273

@breadbox noted – smcg – 2013-12-18T19:39:09.593

+1. I was about to post something like my shell solution: $_='say"lave;\047",~~reverse,"\047=_\$"';eval, but your solution is shorter :-) Note that you can golf it down to 39 characters using say. Hope you will beat all the esoteric weirdness :-)

– Tomas – 2014-02-01T20:26:50.970

@Tomas are you suggesting replacing print with say? That ends up not printing anything. – smcg – 2014-02-03T14:58:55.837

Did you run perl with -Mfeature=say option? – Tomas – 2014-02-03T15:19:33.817

No, I didn't. I don't know if that would count against my score or not. – smcg – 2014-02-03T16:11:54.527

9

Fission, 6 bytes

A rare case of a generalised quine that is the same length as the normal quine:

"LO+!'

The idea is the same as that of the normal quine, but we're using a left-going atom (starting at the L) so that print mode traverses the code in the opposite order.

Martin Ender

Posted 2013-12-18T15:47:30.867

Reputation: 184 808

8

J: 26

Standard quining (26 chars): by defining a function and passing it its own definition, in quotes:

|.(,],2#{:)'|.(,],2#{:)'''

Could probably be made shorter.

J-specific (33 chars): by defining a variable and asking what file the variable was defined in, i.e. this one, then printing out the contents of that file:

1!:2&2|.1!:1(4!:4 a=:<'a'){4!:3''

Must be saved & run from a script (i.e. not in the REPL, because then the answer to the question is "your argument wasn't defined in a file", so there's no file to read).

Dan Bron

Posted 2013-12-18T15:47:30.867

Reputation: 421

2The second one should get the + 25 bonus to read the own file. – Johannes Kuhn – 2013-12-18T20:04:11.413

2@JohannesKuhn: Penalty, but yeah. – jazzpi – 2013-12-19T10:08:26.583

1"Bonus" sounds nicer. – Johannes Kuhn – 2013-12-19T10:15:50.770

7

Microscript, 11 bytes

I kind of had to do this.

0"Caxq"Caxq

Surprisingly, this is actually shorter than the language's shortest known true quine. q and a are otherwise equivalent, except q adds wrapping quotes while a does not.

SuperJedi224

Posted 2013-12-18T15:47:30.867

Reputation: 11 342

7

><>, 25 bytes

I was surprised to find this hadn't been done yet. :)

...yhsif sllems gnihtemoS

Paste code here and run it.

. is the Jump command, popping x and y off the stack, and moving the IP to (x, y) in the code box. In this case, the stack is empty, so the language's only error message is printed:

Something smells fishy...

mbomb007

Posted 2013-12-18T15:47:30.867

Reputation: 21 944

1The best answer – Insane – 2016-04-24T18:28:33.750

5

JavaScript jQuery 119 92 74 70 characters

alert($("#answer-16051 pre code").text().split("").reverse().join(""))

Now using jQuery, as minitech suggested in the comments, and manually wrapping with <pre><code> so I can use text() without fear of other code blocks in this post interfering. Manually wrapping with <h4> was incompatible with chromeium when I tested it, so now it should work in most browsers.

This program, if run from this page, finds the code block directly above, reverses its contents, and puts it in an alertbox.

Its easy enough to verify, just paste it into the dev console.

AJMansfield

Posted 2013-12-18T15:47:30.867

Reputation: 2 758

I like this solution; thinking outside the box. – theonlygusti – 2015-04-13T17:35:59.810

This is way longer than just using a function. And you should use jQuery (on this page) or at least querySelector anyways… – Ry- – 2013-12-19T17:58:47.030

@minitech thanks for the tip, I swapped it for a querySelector now. I would like to look into the jQuery possibility, but it looks like it will take a little longer for me to figure out. – AJMansfield – 2013-12-19T18:37:03.950

@minitech ok, thanks for the jQuery tip. (I only started learning javascript yesterday.) – AJMansfield – 2013-12-19T18:45:56.013

4

PHP, 41 characters (+25)

Don't know if I understood the assignment correctly. But here's a PHP try:

while(!isset($s) || $s) echo isset($s) ? array_pop($s) : ($s = str_split(file_get_contents(__FILE__)) and null);

edit: this can be much shorter:

echo strrev(file_get_contents(__FILE__));

But since it can be that simple, this is probably not what is being asked...

nl-x

Posted 2013-12-18T15:47:30.867

Reputation: 306

phpFiddle: http://phpfiddle.org/main/code/fuy-mv0

– nl-x – 2013-12-18T20:24:32.080

When I click run, I get a whole bunch of useless nonsense (here is a short snippet of it: >? ;)llun dna ))__ELIF__(f$(tilps_rts = s$( : )s$(pop_yarra ? )s$(tessi ohce )s$ || )s$(tessi!(elihw ;"stnetnoc_"=.f$ ;'teg_elif'=f$ php?<>?}};ESLAF nruter;"ec6x\i66x\02x\e47x\96x\rw; there is much much more). Also, include your character count; this is a code golf. Also, it seems that you are reading your source file, so add 25 to your character count and that is your score. Lowest score wins. – Justin – 2013-12-18T21:30:26.863

@Quincunx First off, it is backwards ... but secondly, this is the source code that phpfiddle generates! (but backwards...) They seem to escape a lot of thing, trying to keep things safe. Replace array_pop with array_shift to see the source code not backwards... – nl-x – 2013-12-18T21:33:14.843

Yes I can see the reversed source code, but what is with all the extraneous text? There are a lot of escape sequences, but there are some that aren't (eg: ESLAF nruter ie return FALSE). – Justin – 2013-12-18T21:36:33.183

@Quincunx Sorry, I'm not catching if you are showing interest in the way phpFiddle works, or if you are criticizing my code. If it's the latter, then in my defense, put my code in a .php file and run it in a browser, and it'll work cleanly. I just thought phpfiddle was a nice thing to let you see, so you can see a bit of it's inner workings. – nl-x – 2013-12-18T21:42:27.623

Sorry if it seems I am criticizing. I was just confused by the extraneous detail. Also, with your new version, please state the character count (41) and include the +25 (for total of 66) for reading the file. – Justin – 2013-12-18T21:49:08.633

This is tagged as [tag:code-golf] – Justin – 2013-12-18T21:59:23.237

4

MATLAB, 78 characters:

 
|
.snoisserpxe ro stnemetats BALTAM ni dilav ton si retcarahc tupni ehT :rorrE

Note that the solution requires you to begin with a special character (alt+0160) and that it prints exactly the reversed message. (Unlike the python solution)

Dennis Jaheruddin

Posted 2013-12-18T15:47:30.867

Reputation: 1 848

4

UNIX shell, 31

Real solution at 52 characters:

A='printf "A$ lave;\047`echo $A|rev`\047=A"';eval $A

But beware! Honesty doesn't pay off in today's world! Penalty is too low!!

6 chars + 25 = 31:

rev $0

Tomas

Posted 2013-12-18T15:47:30.867

Reputation: 2 333

On OSX rev $0 generates the error: rev: illegal option -- b. – kenorb – 2014-07-21T13:21:02.187

4

MS-DOS, 24 bytes

eman elif ro dnammoc daB

Output:

Bad command or file name

Neil

Posted 2013-12-18T15:47:30.867

Reputation: 95 035

3

JavaScript, 62

function f(){alert((f+'f()').split('').reverse().join(''))}f()

Works for me on latest Chrome (v 31.0.1650.63). Some other browsers may give a different output. (If you reverse that output, then it would work :P)

Doorknob

Posted 2013-12-18T15:47:30.867

Reputation: 68 138

3

SmileBASIC, 118 102 bytes

FOR I=-101TO.?MID$(("+CHR$(34))*3,30,102)[-I];:NEXTFOR I=-100TO.?MID$(("+CHR$(34))*3,30,102)[-I];:NEXT

12Me21

Posted 2013-12-18T15:47:30.867

Reputation: 6 110

3

Japt, 12 bytes

"iQ ²w"iQ ²w

Try it online!

Based off the standard Japt quine

Explanation

"iQ ²w"      // Take this string.        iQ ²w
       iQ    // Insert a quote.          "iQ ²w
          ²  // Double.                  "iQ ²w"iQ ²w
           w // Reverse.                 w² Qi"w² Qi"
             // Implicitly output.

ASCII-only

Posted 2013-12-18T15:47:30.867

Reputation: 4 687

Congrats on your 5th Japt solution; bounty on its way. – Shaggy – 2019-02-26T13:30:04.443

2@Shaggy wait >_> I wasn't doing this for the bounty – ASCII-only – 2019-02-26T21:32:11.983

1Happy coincidentally for you, so, that there's one going :) – Shaggy – 2019-02-26T22:20:00.920

2

Brain-Flak, 3836 + 3 = 3839

(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()()()()()())(()()())(()()()())(())(()()()()())(()()()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(())(())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()())(()()()())(()())(()())(())(()())(()())(()())(()()()())(()())(()()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()()())(()())(()()()()()()())(())(()()())(()()()()()()())(()()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(())(()()()()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()()()()()())(()()())(()()()())(()()()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()())(())(()())(()())(()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()())(()()()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()()()()()())(()()())(()()()()){({}<>)<>}<>([]){({}[()]<(({}[()]<((((((((()()()()()){}){}){})<>))()))>)<>){({}[()]<({}())>){({}[()]<({}(((()()())){}{}){}())>){({}[()]<({}()())>){({}[()]<({}(((()()()){}()){}){}())>){({}[()]<({}()())>){({}[()]<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}{}([]<({}<{({}<>)<>}<>>)>){({}[()]<({}<>)<>>)}{}{({}[()]<((({}[()])()))>)}{}<>>)}{}{({}<>)<>}<>

Try it online

+3 bytes from the -A flag

This is a very simple variation on the standard Brain-Flak Quine. In fact this variant is obtained by removing bytes from the original Quine. Here is a picture of the original Quine with the removed characters in red:

Code difference

The reason this variation is so simple is that the original Quine builds two parts of the program each on its own stack. One of the two parts is reversed so that when they are joined it becomes un-reversed.

So to make the reverse Quine we simply remove a stack swap.

We also have to remove the part of the program that encodes these two bytes otherwise they will be printed as well.

Post Rock Garf Hunter

Posted 2013-12-18T15:47:30.867

Reputation: 55 382

How come the -A flag is 3 bytes? – MD XF – 2017-05-30T18:22:49.123

@MDXF The flag is -A you need to add a space to call. For programs that take input you only need plus one because -f can become -fA for one extra byte. – Post Rock Garf Hunter – 2017-05-30T18:24:36.207

I thought the general concensus on compiler/interpreter flags was that they did not have to include the space or the - in the byte count. – MD XF – 2017-05-30T18:25:34.920

1@MDXF No, you do have to include them. – Post Rock Garf Hunter – 2017-05-30T18:41:20.260

2

C, 115 bytes

f(){char*s="f(){char*s=c%s%c%;printf(s+42,34,a,34);};)43,s,43,24+s(ftnirp;%c%s%c=s*rahc{)(f";printf(s+42,34,s,34);}

Haha, this is possible in C! Took me a few hours and nearly cheats, but it gets the job done.

MD XF

Posted 2013-12-18T15:47:30.867

Reputation: 11 605

2

JavaScript, 56

($=_=>_!=$._?_?$(_.slice(1))+_[0]:')':$('($='+$+')('))()

Ry-

Posted 2013-12-18T15:47:30.867

Reputation: 5 283

Please state your environment because this does not work in Chrome. Is this Rhino or what? – George Reith – 2013-12-20T13:39:03.097

@GeorgeReith: Anything with ES6 arrow function support. All SpiderMonkeys should work fine, for example (Rhino included). – Ry- – 2013-12-20T14:42:56.347

2

C, 148

char *a="};)43,b,43,a(ftnirp;]i-57[a=]i[b)++i;67<i;(rof{)(niam;i,]99[b,%c%s%c=a* rahc",b[99],i;main(){for(;i<76;i++)b[i]=a[75-i];printf(a,34,b,34);}

Just a fun play on a typical C quine.

Josh

Posted 2013-12-18T15:47:30.867

Reputation: 2 783

2

CSS, 88 bytes

<style>:before,*{display:block;unicode-bidi:bidi-override;direction:rtl;content:'<style>

Put in a blank html page to avoid conflict with other tags.

Mama Fun Roll

Posted 2013-12-18T15:47:30.867

Reputation: 7 234

2

JavaScript, 53 50 46 43 bytes

q=_=>("q="+q+";q()").split("").reverse().join("");q()

(q=_=>`(q=${q})()`.split("").reverse().join(""))()

(q=_=>`(q=${q})()`.split``.reverse().join``)()

(q=_=>[...`(q=${q})()`].reverse().join``)()

Please help me shorten this up.

ericw31415

Posted 2013-12-18T15:47:30.867

Reputation: 2 229

You don't need the wrapper. q=_=>[...`q=${q}`].reverse().join`` works just as well. – Rɪᴋᴇʀ – 2016-04-22T00:00:01.140

If I remove the wrapper, it will not automatically execute itself. – ericw31415 – 2016-04-22T00:29:11.790

it doesn't need to. Functions are fine. – Rɪᴋᴇʀ – 2016-04-22T01:03:52.713

But then, the code returns the function reference, not the output of the function. – ericw31415 – 2016-04-23T20:16:35.753

@ericw31415 is right. the function call is necessary. – Mama Fun Roll – 2016-04-25T04:07:38.157

2

Fuzzy Octo Guacamole, 4 bytes

KNU_

K prints _UNK, N pushes None, and U pushes 0. And _ pops the top value on the stack (but doesn't print). So only _UNK is printed.

Bald Bantha

Posted 2013-12-18T15:47:30.867

Reputation: 463

Why does K output _UNK? – caird coinheringaahing – 2017-05-22T17:37:57.947

@RandomUser ask Riker for more details, he's the language's creator. I just read the docs. – Bald Bantha – 2017-05-22T22:04:20.053

1

><>, 10 8 bytes

2 bytes saved thanks to @JoKing by using ' strings instead of " strings

'd3*}>o<

Try it online!

Explanation

'd3*}>o<               Push the code points of every character in the string 'd3*}>o<'
d3*                    Computes 39, the code point of ' (13*3)
                       Now the stack contains the quote on top of the stack
}                      Shift the stack to the right, so that the ' will be shifted to the bottom of the stack
                       This is required because the ' needs to be printed last
>o<                    Print everything in the stack until the stack is empty
                       And finally the program ends in an error

user41805

Posted 2013-12-18T15:47:30.867

Reputation: 16 320

Would 00g (rather than 84*2+) count as reading the source code? – Esolanging Fruit – 2017-05-26T02:39:30.247

@Challenger5 I would think so. – user41805 – 2017-05-26T06:12:28.003

How about you use ' instead? 'd3*}>o<?

– Jo King – 2018-01-24T09:31:40.930

@JoKing Thanks, that was a neat find – user41805 – 2018-01-24T18:26:57.610

1

Apple ][ BASIC, 12 bytes

RORRE XATNYS?

Hit the soft RESET key on the emulator to enter BASIC mode.

applejs

Commodore 64 BASIC, 13 bytes

RORRE  XATNYS?

c64js

MD XF

Posted 2013-12-18T15:47:30.867

Reputation: 11 605

@user56656 Being my answer https://codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too.

– sergiol – 2018-03-29T18:39:38.170

@DJMcMayhem Being my answer https://codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too.

– sergiol – 2018-03-29T18:40:11.643

@ike Being my answer https://codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too.

– sergiol – 2018-03-29T18:40:58.817

@sergiol just leaving the comment should be fine (as opposed to pinging three people), I'm willing to delete this if it's invalid. However I disagree that error quines are not allowed by default; this is not asking for a quine, rather a quine variant. I've long thought those two tags should be differentiated. – MD XF – 2018-03-31T01:47:00.760

Additionally, this program defines its own rules for what constitutes as a valid submission as opposed to going along with the "proper quine" rules discussed on the meta. – MD XF – 2018-03-31T01:49:38.243

1

CJam, 12 bytes

{"~_"\`W%}_~

Explanation:

{             e# Push this block literal:
 "~_"         e#   Push the string "~_"
     \        e#   Swap
      `       e#   Escape
       W%     e#   Reverse
         }    e# End
          _   e# Duplicate
           ~  e# Execute

Esolanging Fruit

Posted 2013-12-18T15:47:30.867

Reputation: 13 542

1

Perl, 49 characters

(Note: the actual program is three lines long, the third line being empty.)

print$/,~~reverse<<''x2
print$/,~~reverse<<''x2
 

Newlines can be a little unintuitive when text is reversed: the output starts with two blank lines. A naive user might expect the output to look more like this program, which is actually significantly shorter:

say~~reverse<< x2
say~~reverse<< x2
 

But only first listing is actually correct.

breadbox

Posted 2013-12-18T15:47:30.867

Reputation: 6 893

1

Quantum64

Posted 2013-12-18T15:47:30.867

Reputation: 371

1

JavaScript, 42 bytes

(f=([a,...b]=`(f=${f})()`)=>a?f(b)+a:'')()

Try it online!

Yair Rand

Posted 2013-12-18T15:47:30.867

Reputation: 381

1

Gol><>, 6 bytes

"2ss}H

Try it online!

Same as regular Gol><> quine, except that we just put the 34 at the bottom of the stack, instead of flipping the entire stack.

Bubbler

Posted 2013-12-18T15:47:30.867

Reputation: 16 616

1

Racket 178

(let((l(list->string(reverse(string->list"(let((l(list->string(reverse(string->lista~a~a~))))(q (integer->char 34)))(printf l q l q))"))))(q (integer->char 34)))(printf l q l q))

Output:

))q l q l ftnirp()))43 rahc>-regetni( q())))"))q l q l ftnirp()))43 rahc>-regetni( q())))~a~a~atsil>-gnirts(esrever(gnirts>-tsil(l((tel("tsil>-gnirts(esrever(gnirts>-tsil(l((tel(

Using the powerful printf makes it almost cheating (though I see people pulling their own sources for only 25 penalty.)

Sylwester

Posted 2013-12-18T15:47:30.867

Reputation: 3 678

1

Pepe, 7 bytes

!RORRER

Link to interpreter (paste the code above, link removes the ! and O)

Explanation:

The interpreter ignores characters other than R,r,E,e so the code is:

RRRER

Now to put the code in explanation:

  RE  # Push 0
RR    # (RR flag: doesn't exist)
    R # R doesn't exist, so output RERROR!

u_ndefined

Posted 2013-12-18T15:47:30.867

Reputation: 1 253

1

05AB1E, 15 bytes

0"D34çýR"D34çýR

Try it online.

Or 17 bytes if a default trailing newline isn't allowed:

0"D34çýR?"D34çýR?

Try it online.

Modification of the default 0"D34çý"D34çý by adding R.

Explanation:

0                   # Push 0 to the stack
                    #  STACK: [0]
 "D34çýR"           # Push the string 'D34çýR' to the stack
                    #  STACK: [0, 'D34çýR']
          D         # Duplicate this string
                    #  STACK: [0, 'D34çýR', 'D34çýR']
           34ç      # Push '"' to the stack
                    #  STACK: [0, 'D34çýR', 'D34çýR', '"']
              ý     # Join the stack by this '"' delimiter
                    #  STACK: ['0"D34çýR"D34çýR']
               R    # Reverse the top value on the stack:
                    #  STACK ['Rýç43D"Rýç43D"0']
                    # (Output the top of the stack implicitly)

Kevin Cruijssen

Posted 2013-12-18T15:47:30.867

Reputation: 67 575

Your first TIO link is returning 1 for me. I assume you're avoiding the boring 2-byte solution? :P

– Oliver – 2019-02-25T21:28:52.850

1

@Oliver Ah, my first TIO link was a copy-paste error from another quine challenge (the one that checks if an input is a substring of the program itself). I've fixed the TIO link, thanks for noticing. As for the 2-byte solution, that is no longer considered a valid quine in the current meta. More information about it here.

– Kevin Cruijssen – 2019-02-26T10:49:48.113

1

Oracle SQL, 142 bytes

select
reverse(replace('@''[@'||chr(93)||'''))from dual;','@',q'[select
reverse(replace('@''[@'||chr(93)||'''))from dual;','@',q]'))from dual;

Oracle SQL, 118 bytes

select
reverse(substr(rpad(1,144,'||chr(39)),27))from dual;select
reverse(substr(rpad(1,144,'||chr(39)),27))from dual;

Test in SQL Plus

SQL> set lines 80 pages 0
SQL> select
  2  reverse(replace('@''[@'||chr(93)||'''))from dual;','@',q'[select
  3  reverse(replace('@''[@'||chr(93)||'''))from dual;','@',q]'))from dual;
;laud morf))']q,'@',';laud morf))'''||)39(rhc||'@[''@'(ecalper(esrever
tceles['q,'@',';laud morf))'''||)39(rhc||'@[''@'(ecalper(esrever
tceles


SQL> select
  2  reverse(substr(rpad(1,144,'||chr(39)),27))from dual;select
  3  reverse(substr(rpad(1,144,'||chr(39)),27))from dual;
;laud morf))72,))93(rhc||',441,1(dapr(rtsbus(esrever
tceles;laud morf))72,))93(rhc||',441,1(dapr(rtsbus(esrever
tceles

Dr Y Wit

Posted 2013-12-18T15:47:30.867

Reputation: 511

1

Gol><>, 6 bytes

sP#Hr"

This is just another way of doing a reverse quine, similar to Bubbler's answer

Try it online!

KrystosTheOverlord

Posted 2013-12-18T15:47:30.867

Reputation: 681

1

Keg, 16 bytes (SBCS)

`÷^℠⅀:,.`÷^℠⅀:,.

Outputs:

.,:⅀℠^÷`.,:⅀℠^÷`

Explained

`÷^℠⅀:,.`÷^℠⅀:,.

`÷^℠⅀:,.`           #Push the string '÷^℠⅀:,.'
÷^                  #Item split string and reverse stack
℠⅀                  #Summate it all into a string
:,.                 #Standard Keg quine procedure

Try it online!

Lyxal

Posted 2013-12-18T15:47:30.867

Reputation: 5 253

1

beeswax,22 bytes

This is a variant of my beeswax quine (golf you a quine for great good!), also using beeswax’ ability to modify its own code.

J~@D@~1~M.8~3@.+~++~4*

GitHub repository to my beeswax interpreter written in Julia.

M L

Posted 2013-12-18T15:47:30.867

Reputation: 2 865

0

Alice, 10 bytes

"9&o57*to@

Try it online!

Explanation

"9&o57*to@"   Push code points of the entire program except the " to the stack.
9&            Execute the next command 9 times.
o             Print 9 characters from top to bottom (i.e. in reverse order).
57*           Compute 5*7 = 35.
t             Decrement to 34 (the code point of ").
o             Print the quote.
@             Terminate the program.

I'm not 100% sure whether this is optimal. 4 bytes to compute 34 seems painful and while I've found a whole bunch of 4-byte alternatives, I haven't found anything in 3 bytes yet. Some of those alternatives (some of these give other results, but they're 34 (mod 256)):

aN4Y
7aRY
5R1Y
4Pa+
7PYN

Martin Ender

Posted 2013-12-18T15:47:30.867

Reputation: 184 808

0

CJam, 10 bytes

"W%_`"W%_`

Try it online!

Alternatively:

"`W%_"_W%`

Explanation

"W%_`"   e# Push this string which contains the code after the string.
W%       e# Reverse the string.
_        e# Duplicate it.
`        e# Stringify the copy which wraps it in quotes. The unquoted and
         e# quoted versions are then implicitly printed to STDOUT back to back.

In the alternative solution, the string itself already contains the code in reverse and then we only reverse the copy (i.e. the string representation). It's kinda neat that it's then just one character off from being a palindrome.

Martin Ender

Posted 2013-12-18T15:47:30.867

Reputation: 184 808

0

Java 8 (function), 144 bytes

v->{String s="v->{String s=%c%s%1$c;return new StringBuffer(s.format(s,34,s)).reverse();}";return new StringBuffer(s.format(s,34,s)).reverse();}

Try it online.

Java 8 (full program), 240 bytes

interface M{static void main(String[]a){String s="interface M{static void main(String[]a){String s=%c%s%1$c;System.out.print(new StringBuffer(s.format(s,34,s)).reverse());}}";System.out.print(new StringBuffer(s.format(s,34,s)).reverse());}}

Try it online.

Explanation:

  • The String s contains the unformatted source code.
  • %s is used to input this String into itself with the s.format(...).
  • %c, %1$c and the 34 are used to format the double-quotes.
  • s.format(s,34,s) puts it all together.

And then new StringBuffer(...).reverse() is used to reverse this source code.

Kevin Cruijssen

Posted 2013-12-18T15:47:30.867

Reputation: 67 575

0

Wumpus, 11 bytes

"@o&l]=43#"

Try it online!

Explanation

In Wumpus, the IP gets reflected off the boundaries of the grid, so without any further control flow redirection, a program on a single line will bounce back and forth through the code.

"@o&l]=43#"    Push the individual code points of this string to the stack.
               This gives us the entire code except the quotes.
               The IP then bounces off the end and starts moving back through
               the code. Since the " ended string mode, this time around the
               code will actually be executed.
#34            Push 34, the code point of double quotes.
=              Duplicate.
]              Shift one copy to the bottom of the stack.
l              Push the stack depth (i.e. the program length 11).
&o             Print that many characters.
@              Terminate the program.

Martin Ender

Posted 2013-12-18T15:47:30.867

Reputation: 184 808

0

Python 2, 38 bytes


s="print's cexe;%r=s'%s[::-1]";exec s

Try it online!

totallyhuman

Posted 2013-12-18T15:47:30.867

Reputation: 15 378

0

Haskell, 66 bytes

main=putStr$reverse$s++show s;s="main=putStr$reverse$s++show s;s="

Try it online!

totallyhuman

Posted 2013-12-18T15:47:30.867

Reputation: 15 378

64 bytes: Try it online!

– Laikoni – 2018-03-24T01:18:01.227

0

PHP, 59

34 + 25 for reading own sourcecode.

<?=strrev(join(file((__FILE__))));

Online demo

HamZa

Posted 2013-12-18T15:47:30.867

Reputation: 161

1Doesn't this get the 25 penalty? – ike – 2013-12-19T15:25:22.150

@ike you're right, I edited accordingly – HamZa – 2013-12-19T20:58:41.093

0

Tcl, 38 bytes

puts [string rev [read [open $argv0]]]

Try it online!

sergiol

Posted 2013-12-18T15:47:30.867

Reputation: 3 055

0

Ruby, 33+25=58

print File.read(__FILE__).reverse

Ajedi32

Posted 2013-12-18T15:47:30.867

Reputation: 143

0

Lua, 31 Characters

'''' raen rorre xatnys :1:tupni

Freesnöw

Posted 2013-12-18T15:47:30.867

Reputation: 109

1Looks like lua to me, on LUA it says STDIN:1: syntax error near 'rorre' – mniip – 2014-01-31T04:52:47.183

0

J, 24 Bytes

(|.@,quote)'(|.@,quote)'

Evaluates to the string ')etouq,@.|(')etouq,@.|(

Try it online! Uses echo in order to print result.

Alternatively, if a full program is required:

(echo@|.@,quote)'(echo@|.@,quote)'

Is 34 bytes and prints ')etouq,@.|@ohce(')etouq,@.|@ohce(

Explanation:

Both of these work in the same way:

(|.@,quote)'(|.@,quote)' | Expression to be evaluated
           '(|.@,quote)' | String literal containing the code
(         )              | Hook, (f g) y is evaluated as y f (g y)
     quote               | Wrap the string in quotes
    ,                    | Append to the unquoted version
 |.@                     | Reverse the whole thing

Bolce Bussiere

Posted 2013-12-18T15:47:30.867

Reputation: 970

0

Stax, 14 bytes

"r34b4l"r34b4l

Run and debug it

Yet another adaption of the "34bL"34bL quine.

Weijun Zhou

Posted 2013-12-18T15:47:30.867

Reputation: 3 396

0

Jelly, 2 bytes

1-

Try it online!

Short but boring.

1 gets ignored when - makes -1 the argument which gets printed.

Jelly, 8 bytes

“ṚṾȮ”ȮṾṚ

Try it online!

(More) interesting but long.

“ṚṾȮ” is a string literal for ṚṾȮ. Ȯ prints the string and returns it. unevals the string, yielding the string “ṚṾȮ” (with the quote characters “” as part of the string). reverses this string and its result, ”ȮṾṚ“ implicitly gets printed.

dylnan

Posted 2013-12-18T15:47:30.867

Reputation: 4 993

0

Befunge-93 (FBBI), 13 bytes

">:#,_98+2*,@

Try it online!

Relies on nonstandard interpreter behavior. Works pretty much the same as this answer, except it's reversed.

osuka_

Posted 2013-12-18T15:47:30.867

Reputation: 391

0

JavaScript, 33 32 bytes

f=([c,...s]='f='+f)=>c?f(s)+c:''

Recursively reverses the string by first providing the quine as the default argument. This beats the syntax error version, which isn't even consistent between browsers.

kamoroso94

Posted 2013-12-18T15:47:30.867

Reputation: 739

0

MS SQL Server 2017, 173 bytes

declare @ char=1
select
reverse(substring(left(@+replicate('+char(39),3),201),28,174))
declare @ char=1
select
reverse(substring(left(@+replicate('+char(39),3),201),28,174))

Output:

))471,82,)102,)3,)93(rahc+'(etacilper+@(tfel(gnirtsbus(esrever
tceles
1=rahc @ eralced
))471,82,)102,)3,)93(rahc+'(etacilper+@(tfel(gnirtsbus(esrever
tceles
1=rahc @ eralced

Try it on db<>fiddle!

Andrei Odegov

Posted 2013-12-18T15:47:30.867

Reputation: 939

0

Matlab, 111

function d=g();d='gvodujpo!e>h)*<e>(<e>gmjqms)\e)2;29*.2-e-e)29;foe*.2^*<';d=fliplr([d(1:18)-1,d,d(18:end)-1]);

knedlsepp

Posted 2013-12-18T15:47:30.867

Reputation: 266

0

Bash, 8 + 25 for reading source = 33 bytes

rev "$0"

31 for no space in path to file

rev $0

NoOneIsHere

Posted 2013-12-18T15:47:30.867

Reputation: 1 916

0

Help, WarDoq!, 2 bytes + 25 = 27

 q

The space is needed.

  • Minimum code length is two characters.

Erik the Outgolfer

Posted 2013-12-18T15:47:30.867

Reputation: 38 134

Help, WarDoq! was created (years) after this challenge was posted, so you should add a disclaimer stating that it's non-competing. Also, it reads its own source code via the q built-in, so I think this is subject to the +25 bytes penalty. – Dennis – 2016-06-16T15:39:55.617

@Dennis I will add them. Thanks for pointing, although there is no other way to make quines here. – Erik the Outgolfer – 2016-06-17T07:28:25.190