I was reading Print your code backwards - reverse quine And I thought, this could be more interesting if your backwards code is also executable. So this challenge will have all the rules and requirements of the other, but must also be valid source once reversed (in the same or another language and still print its source backwards.

All rules and scoring from the reverse quine challenge apply, so all answers to this question will answer that one (but not score as well.)


By request, all rules now copied here.


  • write a program p which when executed produces output p' where p' is p backwards and p' when executed produces p.
  • No using other files (e.g. reverse.txt)
  • Minimum code length is two characters.
  • Your program cannot be a palindrome.


  • +50 if you use pull data from the Internet.
  • +25 if you read your own source code.
  • +1 point per character.
  • Lowest score wins.
  • \$\begingroup\$ eval(eval(eval(eval(eval(eval(eval(eval(eval(p))))))))) \$\endgroup\$ – Andrew Larsson Dec 19 '13 at 1:18
  • \$\begingroup\$ I'm just saying that you'd be able to execute the output of executing the output of executing the output of [...] executing the output of p (same as any quine except for the backwards quine). \$\endgroup\$ – Andrew Larsson Dec 19 '13 at 1:21
  • \$\begingroup\$ @AndrewLarsson Indeed although The proof of concept I am building p will be written in c and p' in perl. \$\endgroup\$ – hildred Dec 19 '13 at 1:23
  • \$\begingroup\$ Oh, that'd be cool! \$\endgroup\$ – Andrew Larsson Dec 19 '13 at 1:23
  • 1
    \$\begingroup\$ Yeah, saw that too late. Not a duplicate. \$\endgroup\$ – Johannes Kuhn Dec 19 '13 at 8:31

GolfScript, 46 chars


Well, this is ugly, but it works. The output equals the code reversed, and is also a valid GolfScript program which outputs the original code again.

OK, let me try to explain how I constructed it. First, I started from the quine {".~"}.~, and modified it as in this answer to reverse itself. To make the output an executable quine in itself, I made a copy of the code before reversing it, and included a # at the end of the code, so that the reversed version at the end became just a comment. Thus, we get the palindromic quine:


However, by the rules, palindromes are not allowed, so I needed to break the symmetry somehow. I figured the easiest way would be to include a 0 (which, in itself, is a quine in GolfScript) in the code and flip it to 1 with ! after creating the reversed copy. Most of the remaining complexity is just ugly stack manipulation to get everything in the right order.

  • \$\begingroup\$ Is it also golfscript when reversed or is it another language? \$\endgroup\$ – hildred Dec 19 '13 at 3:37
  • \$\begingroup\$ Yes, it's GolfScript both ways. Indeed, except for the 0 and 1 at the beginning and end, the rest of the code is a palindrome. \$\endgroup\$ – Ilmari Karonen Dec 19 '13 at 3:43
  • 9
    \$\begingroup\$ Wow. Okay, I don't feel smart enough for this SE anymore :( \$\endgroup\$ – Cruncher Dec 19 '13 at 14:34

Perl and C 6478 1955

#!/usr/bin/perl -i//
$_=<<'rahc';eval $_; #//
print scalar reverse "#!/usr/bin/perl -i//\n\$_=<<'rahc';eval \$_; #//\n${_}rahc\n" #//
__END__ enifed#
};)"{ = ][cn\rahcn\n\"(p
};)'n\'( rahctup) 1 == 21%b ( fi
;)d(p;)]1-b[c,",d%",)d(foezis,d( ftnirpns{)b--;b;)c(foezis=b( rof
;)c(p;]9[d rahc;b tni{)(niam diov
}};)]1-b[c(rahctup )]1-b[c(fi{)b--;b;)c(nelrts=b(rof;b tni{)c*rahc(p diov
>h.gnirts< edulcni#
>h.oidts< edulcni#
{ = ][c


Brief explanation: from perl the two interesting lines are the second and the third. The second line has two statements the first of which reads the rest of the document into a string. The second evals the string. The Third line prints everything backwards. every thing else gets ignored. from the c side you have an array which has the program as a string, which gets printed as an array and a string, and the rest is a comment.

  • 1
    \$\begingroup\$ wat. :O My head exploded. But I count 6536 characters in that... \$\endgroup\$ – Doorknob Dec 19 '13 at 2:08
  • \$\begingroup\$ What...how... 0_0 \$\endgroup\$ – The Guy with The Hat Dec 19 '13 at 2:15
  • \$\begingroup\$ @DoorknobofSnow I counted the wrong version. But here is a shorter version. \$\endgroup\$ – hildred Dec 19 '13 at 7:22
  • \$\begingroup\$ This is incredible! I think Haskell/C might be another feasible combination. \$\endgroup\$ – theonlygusti Apr 13 '15 at 17:25
  • \$\begingroup\$ @theonlygusti, if you post it and I can compile it, I will upvote it. \$\endgroup\$ – hildred Apr 13 '15 at 17:28

Ruby 145

DATA.read.tap{|a|puts a.reverse,a.tr("\x79\x59","\x59\x79")}
})"97x\95x\","95x\97x\"(rt.a,esrever.a stup|a|{pat.daer.ATAD

The main idea is simple: just put the first half of the source code backwards after the __END__ which can be read using DATA from ruby. Then just print the reverse of this data, then print the data, and you get back the original source code

The problem is, that this becomes a palindrome (note that the first line needs an endline), so we have to break the symmetry. I just added a symbol :y to the code, and some code that will transform this symbol between lowercase and uppercase between runs, thereby reverting to the original state after two runs.

Test one: they can be executed

$ ruby rq2.rb > rq2t.rb
$ ruby rq2t.rb > rq2tt.rb

Test two: the result of two runs will return the original source

$ diff rq2.rb rq2tt.rb

Test three: the code is not a palindrome (the middle run is different)

$ diff rq2.rb rq2t.rb
< :y
> :Y
< Y:
> y:

Gol><>, 11 bytes


A whole byte chopped off! it almost is a palindrome, but technically isn't because of the '+' and '-', haha!

Try it online!

The two below don't work, or at least they don't meet the specifications of the challenge, but the code above does.

slightly younger version, 12 bytes


Golfed off a byte, simply by using the double quote and incrementing it by 5! And this new version looks less like a palindrome.

Try it online!

older version, 13 bytes


There was a problem with the previous that JoKing pointed out, thank you for that, now it works, but with the price of 4 extra bytes...

Try it online!


><>, 21 19 bytes

'rd3*70.r l?!;o90.<

Try it here!

Uses the *><> interpreter for convenience, but this is valid ><> code.

If erroring out is allowed, then it can be done in 16 bytes:

'd3*}70.!r  !|o|

Try it here!

  • \$\begingroup\$ @JoKing thank you! It was 7am and I was just too tired to put that together. I'll edit it in, in a couple hours. \$\endgroup\$ – Discordian Sep 17 '18 at 18:58
  • \$\begingroup\$ "Try it" links are dead. \$\endgroup\$ – pppery Jan 5 '20 at 4:55
  • \$\begingroup\$ @pppery thanks, fixed. \$\endgroup\$ – Discordian Jun 16 at 16:24

Help, WarDoq! (27 bytes)

25 bytes added because of reading source code.


How it works:
<space> - a comment that ends on non-space character
q - print source code reversed (q"space")



How it works:
q - print source code reversed (q for now)
<space> - a comment that ends on non-space character, and add a character to beginning of q command (making "space"q)


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.