83
\$\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\$
  • 1
    \$\begingroup\$ Looks like this has been done before, just without the "no palindromes" rule. \$\endgroup\$ – Iszi Dec 18 '13 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\$ – AJMansfield Dec 18 '13 at 20:24
  • 7
    \$\begingroup\$ @AJMansfield Lowest score wins means that +x would be a penalty, -x would be a bonus. \$\endgroup\$ – Iszi Dec 18 '13 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\$ – AJMansfield Dec 18 '13 at 20:35
  • 4
    \$\begingroup\$ Woohoo, 1st place on the hot network questions list :D Our site needs more attention... \$\endgroup\$ – Doorknob Dec 19 '13 at 0:09

66 Answers 66

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\$
  • \$\begingroup\$ How come the -A flag is 3 bytes? \$\endgroup\$ – MD XF May 30 '17 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\$ – Sriotchilism O'Zaic May 30 '17 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 May 30 '17 at 18:25
  • 1
    \$\begingroup\$ @MDXF No, you do have to include them. \$\endgroup\$ – Sriotchilism O'Zaic May 30 '17 at 18:41
2
+200
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ Congrats on your 5th Japt solution; bounty on its way. \$\endgroup\$ – Shaggy Feb 26 at 13:30
  • 2
    \$\begingroup\$ @Shaggy wait >_> I wasn't doing this for the bounty \$\endgroup\$ – ASCII-only Feb 26 at 21:32
  • 1
    \$\begingroup\$ Happy coincidentally for you, so, that there's one going :) \$\endgroup\$ – Shaggy Feb 26 at 22:20
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\$

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

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\$
  • \$\begingroup\$ Would 00g (rather than 84*2+) count as reading the source code? \$\endgroup\$ – Esolanging Fruit May 26 '17 at 2:39
  • \$\begingroup\$ @Challenger5 I would think so. \$\endgroup\$ – Cows quack May 26 '17 at 6:12
  • \$\begingroup\$ How about you use ' instead? 'd3*}>o<? \$\endgroup\$ – Jo King Jan 24 '18 at 9:31
  • \$\begingroup\$ @JoKing Thanks, that was a neat find \$\endgroup\$ – Cows quack Jan 24 '18 at 18:26
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\$
  • \$\begingroup\$ Your first TIO link is returning 1 for me. I assume you're avoiding the boring 2-byte solution? :P \$\endgroup\$ – Oliver Feb 25 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\$ – Kevin Cruijssen Feb 26 at 10:49
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\$
  • 1
    \$\begingroup\$ Doesn't this get the 25 penalty? \$\endgroup\$ – ike Dec 19 '13 at 15:25
  • \$\begingroup\$ @ike you're right, I edited accordingly \$\endgroup\$ – HamZa Dec 19 '13 at 20:58
0
\$\begingroup\$

Lua, 31 Characters

'''' raen rorre xatnys :1:tupni
\$\endgroup\$
  • 1
    \$\begingroup\$ Looks like lua to me, on LUA it says STDIN:1: syntax error near 'rorre' \$\endgroup\$ – mniip Jan 31 '14 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\$
0
\$\begingroup\$

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

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.

\$\endgroup\$
0
\$\begingroup\$

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.

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

Python 2, 38 bytes


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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Haskell, 66 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Tcl, 38 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Help, WarDoq!, 2 bytes + 25 = 27

 q

The space is needed.

  • Minimum code length is two characters.
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Dennis Jun 16 '16 at 15:39
  • \$\begingroup\$ @Dennis I will add them. Thanks for pointing, although there is no other way to make quines here. \$\endgroup\$ – Erik the Outgolfer Jun 17 '16 at 7:28
0
\$\begingroup\$

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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