# Backwards and forwards polyglot quine!

You must make a polyglot that outputs its source code in one language and its source code backward in another. Unlike the normal rules, you are allowed to read the current file or use a builtin to get the source code of your submission and reverse that in one language. Your source code cannot be a palindrome.

For example, if your source code is abcxyz, it must output abcxyz in one language and zyxcba in another. If your code is abcxyzyxbca, it's invalid because it's a palindrome.

Good luck!

• Normal rules are there for a reason. Allowing quine built-ins will likely make this challenge too broad, and allowing palindrome source codes allows answers which are forward quines for both languages. – Erik the Outgolfer Apr 24 '17 at 11:43
• @EriktheOutgolfer palindromes are now not allowed. – programmer5000 Apr 24 '17 at 11:44
• @EriktheOutgolfer Ah, so the source code cannot be a palindrome? – Luis Mendo Apr 24 '17 at 11:52
• I think you should offer a bounty for the first person to complete this challenge without breaking any of the normal quine rules. (maybe 50 rep?) – Qwerp-Derp Apr 24 '17 at 12:13
• I read "in one language" as clearly disallowing the case where both languages read the source code, but the current top-voted answer does exactly that. Can you edit to make it clear whether that's meant to be allowed? – hvd Apr 24 '17 at 21:44

## PHP & GolfScript, 2 bytes


1


i.e. a newline and the digit 1.

This is a reverse quine in GolfScript, contributed on this site by Justin. PHP hasn't triggered that it's a programming language so it prints its input.

# Python 2 / Python 3, 71 bytes

lambda _='lambda _=%r:(_%%_)[::int(1-(1/2)*4)]':(_%_)[::int(1-(1/2)*4)]


Does not use any quine builtins.

Thanks to ovs for generally awakening me.

• lambda _='lambda _=%r:(_%%_)[::int(1-(1/2)*4)]':(_%_)[::int(1-(1/2)*4)] for 71 bytes – ovs Apr 24 '17 at 12:48
• @ovs Oh of course, how I didn't think of that. – Erik the Outgolfer Apr 24 '17 at 12:49

## Batch / bash + tac, 39 bytes

:;tac -r -s '.\|'$'\n'$0;exit
@type %0


Outputs forwards in Batch. Explanation: Batch sees the first line as a label and ignores it, while the second line simply copies the source file to STDOUT. (Note that you need to invoke the file including extension, or change %0 to %~f0.) bash sees four commands:

• : does nothing (same as true)
• tac -r -s '.\|'$'\n'$0
• -r puts tac into regex mode
• -s specifies a regex
• '.\|'$'\n' is the regex, composed of • . any character except newline • \| or • $'\n' a newline
• The upshot is that tac splits the file into characters rather than lines.
• exit stops the script, ignoring the fourth command
• @type %0 (ignored)
• I think that you can replace the first line with :;rev $0|tac;exit. Also, the header should say Batch / sh + util-linux + coreutils instead. – Erik the Outgolfer Apr 24 '17 at 12:01 • @EriktheOutgolfer $'\n' is a Bashism, rev $0|tac doesn't reverse newlines correctly, and does it really matter that tac comes in a package? – Neil Apr 24 '17 at 12:23 • $'\n' doesn't exist in the replacement I've suggested, and rev $0|tac works for me. And I think it's better to specify the packages instead of the individual utilities, because sometimes confusion might arise (e.g. which package's tac?). – Erik the Outgolfer Apr 24 '17 at 12:29 • @EriktheOutgolfer Try it online! is wrong. So is Try it online! (but more subtly). – Neil Apr 24 '17 at 12:31 • Could you please give an explanation? – programmer5000 Apr 24 '17 at 12:34 # PHP & Retina, 2 bytes  1  The same as Gille's PHP & GolfScript answer. PHP just reads the code and outputs it directly, Retina will replace matches of an empty string in the input and replace it with 1, and output that with a newline. # JS (ES5), JS (ES6), 94 bytes function f(){try{eval("x=(f+'f()').split.reverse().join")}catch(e){x=f+"f()"};return x}f()  Does not use any quine built-ins. Just uses the fact that JS functions stringify to their code. Probably can be golfed more. If you allow reading the source code, it isn't really a quine. ## PHP & sh+util-linux, 6 bytes rev$0


I'm sure that the usual golfing languages can do it in 2 bytes.

• They infact can. – ATaco Apr 26 '17 at 0:16