88
\$\begingroup\$

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.
\$\endgroup\$
13
  • 1
    \$\begingroup\$ Looks like this has been done before, just without the "no palindromes" rule. \$\endgroup\$
    – Iszi
    Commented Dec 18, 2013 at 18:59
  • 3
    \$\begingroup\$ Are 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. \$\endgroup\$ Commented Dec 18, 2013 at 20:24
  • 8
    \$\begingroup\$ @AJMansfield Lowest score wins means that +x would be a penalty, -x would be a bonus. \$\endgroup\$
    – Iszi
    Commented Dec 18, 2013 at 20:32
  • 9
    \$\begingroup\$ The one question I have, then, is why is pulling data from the internet given a larger penalty than reading the source file? \$\endgroup\$ Commented Dec 18, 2013 at 20:35
  • 5
    \$\begingroup\$ Woohoo, 1st place on the hot network questions list :D Our site needs more attention... \$\endgroup\$
    – Doorknob
    Commented Dec 19, 2013 at 0:09

72 Answers 72

2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ You don't need the wrapper. q=_=>[...`q=${q}`].reverse().join`` works just as well. \$\endgroup\$
    – Riker
    Commented Apr 22, 2016 at 0:00
  • \$\begingroup\$ If I remove the wrapper, it will not automatically execute itself. \$\endgroup\$
    – ericw31415
    Commented Apr 22, 2016 at 0:29
  • \$\begingroup\$ it doesn't need to. Functions are fine. \$\endgroup\$
    – Riker
    Commented Apr 22, 2016 at 1:03
  • \$\begingroup\$ But then, the code returns the function reference, not the output of the function. \$\endgroup\$
    – ericw31415
    Commented Apr 23, 2016 at 20:16
  • \$\begingroup\$ @ericw31415 is right. the function call is necessary. \$\endgroup\$ Commented Apr 25, 2016 at 4:07
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Why does K output _UNK? \$\endgroup\$ Commented May 22, 2017 at 17:37
  • \$\begingroup\$ @RandomUser ask Riker for more details, he's the language's creator. I just read the docs. \$\endgroup\$ Commented May 22, 2017 at 22:04
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ How come the -A flag is 3 bytes? \$\endgroup\$
    – MD XF
    Commented May 30, 2017 at 18:22
  • \$\begingroup\$ @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. \$\endgroup\$
    – Wheat Wizard
    Commented May 30, 2017 at 18:24
  • \$\begingroup\$ 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. \$\endgroup\$
    – MD XF
    Commented May 30, 2017 at 18:25
  • 1
    \$\begingroup\$ @MDXF No, you do have to include them. \$\endgroup\$
    – Wheat Wizard
    Commented May 30, 2017 at 18:41
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ @user56656 Being my answer codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too. \$\endgroup\$
    – sergiol
    Commented Mar 29, 2018 at 18:39
  • \$\begingroup\$ @DJMcMayhem Being my answer codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too. \$\endgroup\$
    – sergiol
    Commented Mar 29, 2018 at 18:40
  • \$\begingroup\$ @ike Being my answer codegolf.stackexchange.com/a/105688/29325 invalid, this one should be too. \$\endgroup\$
    – sergiol
    Commented Mar 29, 2018 at 18:40
  • \$\begingroup\$ @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. \$\endgroup\$
    – MD XF
    Commented Mar 31, 2018 at 1:47
  • \$\begingroup\$ 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. \$\endgroup\$
    – MD XF
    Commented Mar 31, 2018 at 1:49
1
\$\begingroup\$

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

><>, 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
\$\endgroup\$
4
  • \$\begingroup\$ Would 00g (rather than 84*2+) count as reading the source code? \$\endgroup\$ Commented May 26, 2017 at 2:39
  • \$\begingroup\$ @Challenger5 I would think so. \$\endgroup\$
    – user41805
    Commented May 26, 2017 at 6:12
  • \$\begingroup\$ How about you use ' instead? 'd3*}>o<? \$\endgroup\$
    – Jo King
    Commented Jan 24, 2018 at 9:31
  • \$\begingroup\$ @JoKing Thanks, that was a neat find \$\endgroup\$
    – user41805
    Commented Jan 24, 2018 at 18:26
1
\$\begingroup\$

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

Python 2, 38 bytes


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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Jstx, 3 bytes

£↕o

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 42 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

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

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)
\$\endgroup\$
2
  • \$\begingroup\$ Your first TIO link is returning 1 for me. I assume you're avoiding the boring 2-byte solution? :P \$\endgroup\$
    – Oliver
    Commented Feb 25, 2019 at 21:28
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Feb 26, 2019 at 10:49
1
\$\begingroup\$

Gol><>, 6 bytes

sP#Hr"

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

Vyxal D, 6 bytes

`IṘ`IṘ

Try it Online!

Explained

`IṘ`IṘ
`IṘ`   # The string "IṘ"
    I  # appended to a backtick-surrounded version of itself
     Ṙ # Reversed
\$\endgroup\$
0
\$\begingroup\$

Ruby, 33+25=58

print File.read(__FILE__).reverse
\$\endgroup\$
0
\$\begingroup\$

PHP, 59

34 + 25 for reading own sourcecode.

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

Online demo

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Doesn't this get the 25 penalty? \$\endgroup\$
    – ike
    Commented Dec 19, 2013 at 15:25
  • \$\begingroup\$ @ike you're right, I edited accordingly \$\endgroup\$
    – HamZa
    Commented Dec 19, 2013 at 20:58
0
\$\begingroup\$

Lua, 31 Characters

'''' raen rorre xatnys :1:tupni
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Looks like lua to me, on LUA it says STDIN:1: syntax error near 'rorre' \$\endgroup\$
    – mniip
    Commented Jan 31, 2014 at 4:52
0
\$\begingroup\$

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]);
\$\endgroup\$
0
\$\begingroup\$

Bash, 8 + 25 for reading source = 33 bytes

rev "$0"

31 for no space in path to file

rev $0
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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