# Period 2 Reversed Quine

Your task is to write a program that outputs its own source code in reverse. However, when the reversed code is run, it should output the source code, facing the correct direction.

## Example

Say your program is abc. When run, it should output cba. cba, when run, should output abc.

## Rules

Your program should follow all the rules of a proper quine (except for outputting the source code). Palindromes are disallowed.

Random note: I am aware of this but I believe that this challenge is different because the transformed code must have the same properties.

# RProgN, 3 bytes

1
2


Try it online!

### How it works

This exploits a potential flaw in our definition of proper quine:

It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)

Furthermore, a quine must not access its own source, directly or indirectly.

That's obviously the case here, as the output is the reverse of the code and the code is not a palindrome.

RProgN – reverse programmer notation – uses a LIFO stack and prints the items on it in the order they are popped. The two tokens 1 and 2, separated by spaces and/or newlines, get popped in reverse order and are printed separated by a newline.

This prints the reversed program

2
1


which, in turn, prints the original one.

!enilno ti yrT

• I like the URL. – Christopher May 4 '17 at 15:10
• We should get this fixed... I'd post a new answer (based on this comment) on the meta question, but it probably wouldn't get enough attention to compete with the existing answers. – ETHproductions May 4 '17 at 18:03
• @ETHproductions: Do it. I feel there are several problems with our current proper quine definition. (Arguably, my language 7 is a study in edge cases for proper quineness; in addition to this particular case, it can handle quite a few others.) FWIW, I'm not sure this is a proper reverse-quine even by our current definition; the 1 and 2 are clearly encoded by themselves, so the only potential interest is as to what's encoding the newline. (This is different from a 1\n1, in which the two 1s encode each other; that's possibly a proper quine but not a proper reverse-quine.) – user62131 May 5 '17 at 1:02

# Befunge-98, 33 bytes

b3*>1#;-:0g,:#;_@_;#:,g0:-;#1>*b3


Try it online!

• Nice first answer. But use the # to make you header. Also go to Tryitonline.net and get a online interpreter – Christopher May 4 '17 at 16:01
• Also go under the save button and use the codegolf submission one. – Christopher May 4 '17 at 16:02
• I edited it on TIO in the first place I just forgot to add the link but now its added and thanks for the Header tip – IQuick 143 May 4 '17 at 16:02
• Note that the "codegolf submission" option on TIO gives you a starting template, including the header. – Ørjan Johansen May 4 '17 at 16:07
• I thought g was disallowed in Befunge quines, as it reads the program's source directly from memory? – user62131 May 5 '17 at 1:21

## Fission 2, 10 bytes

"L;L'!+!'_


Try it online!

This prints:

_'!+!'L;L"


Try it online!

And vice versa.

### Explanation

This is a modification of the reverse quine. It's working to our advantage here that ! is used for printing and is also only one code point away from the the quote ". That makes it easier to make the quote printing section palindromic (the '!+!'). Let's start with the first code:

"L;L'!+!'_


This program has two entry points at the Ls, which each creates a left-going atom. However, the right one immediately hits the ; which destroys it. The left one enters string mode and wraps around to the end, so that it prints the entire code (except the ") from back to front. That already gives us _'!+!'L;L. All that's left is to print the ". _ can be ignored, '! sets the atom's mass to 33 (the code point of !), + increments it to ", and ! prints it. That's all the output done. The 'L sets the atoms mass to the code point of L but that's irrelevant. ; destroys this atom as well and since no atoms are left, the program terminates.

Now the other way round:

_'!+!'L;L"


Again, we have two entry points but one atom is immediately destroyed. This time we move through the !+!' section first, so we start by printing a quote. The '_ is again irrelevant, but we need the _ (or some other useless character) here to avoid ' escaping the ". The atom wraps to the end, traverses the source code once in string mode to print the rest of the program in reverse, the L is then ignored and ; destroys the atom and terminates the program.