# Reversible program

### Objective

Write a program that outputs some printable ASCII characters. The trick is that if the program is reversed byte-by-byte, it must output the same thing in the reverse order, byte-by-byte, too.

### Rules

• No standard loopholes.
• The program must not be a palindrome, nor can it be 1 byte in length (or empty). No restriction for patterns of the output as long as:
• The output is at least 2 bytes long. It must contain solely printable ASCII characters, including visible characters and newlines, tabs and spaces. It should not be empty.
• Outputs to standard error is ignored.
• Quine programs are forbidden.

For example, the following program makes no sense (HQ9+)

AQ


### Easy Mode

Paired parentheses/brackets/curly brackets are swapped after reversing source, so a reverse may be:

print("Hello");
;("olleH")tnirp  # not ;)"olleH"(tnirp


### Example

These are theoretical examples and may not exist in any programming language.

input -> output

program -> abcd
margorp -> dcba

() -> 10
)( -> 01

print('yes')tnirp -> yes
print('sey')tnirp -> sey


This is a , so the program with the shortest source code (in bytes) in each language wins!

• Surely any cat-like language can do this in 2 bytes? – Neil Sep 15 '17 at 0:31
• @iBug I think you should try sandbox next time. I feel that you just wanted to post your answer without taking sometime to think about other peoples answers (like quines). Also it is not nice to change the rules after 12 answers have been posted... – J42161217 Sep 15 '17 at 0:49
• I see this put on hold but I do not see any comments about how this question can be improved. I'm voting to reopen. – Poke Sep 15 '17 at 1:21
• I don't understand the last test case -- shouldn't it be sey output for the second part? – cole Sep 15 '17 at 2:29
• Why is this challenge still getting downvoted? Please leave a comment if you think this challenge can be improved. – Poke Sep 15 '17 at 18:15

# RProgN 2, 2 bytes

Ai


Forwards, produces ZYXWVUTSRQPONMLKJIHGFEDCBA, backwards, produces ABCDEFGHIJKLMNOPQRSTUVWXYZ.

A pushes the alphabet, and i reverses it, although if i doesn't have anything to reverse, it conveniently does nothing.

Try it online!

# Jelly, 5 bytes

22«33


Try it online!

The first is min(22, 33) and the reverse is min(33, 22)

# Also 5 bytes

.)25½


Try it online!

The ) seems to discard everything before it. This is sqrt(25) which is 5.0 and the reverse is . which is 0.5.

• +1 for the 5.0 vs. 0.5. – Khuldraeseth na'Barya Sep 15 '17 at 0:56

# Rain-Flak, 65 59 bytes

((((((#)])([))(}{)}{))}{))
()()()()(
)){})){}){})())#((((((


Try it online!

This pushes


()



going forwards and


)(



going backwards.

It needs to pad the front with a newline because Brain-Flak's output automatically gets a newline added to the end of the output.

• The language changed its name too? – Jonathan Allan Sep 15 '17 at 4:29
• @JonathanAllan That is the (informal) name of the Ruby interpreter of the language. – Erik the Outgolfer Sep 15 '17 at 11:40
• @JonathanAllan What Erik said is correct. The comment behavior used here is unique to the Ruby interpreter so I specified the interpreter as to avoid confusion. – Sriotchilism O'Zaic Sep 15 '17 at 17:32

# Jelly, 2 bytes

0%


Both full programs output the palindromic nan as they both attempt to take a modulo of zero by zero and implicitly print the result.

# Brain-Flak, 35 28+1=29 bytes

((#)}{))
()()()()(
)){})#((


1 extra byte because of the flag -A to print ascii. This prints "\n\n"

Try it online!

-6 bytes thanks to Riley pointing out that I can cleverly use newlines in order to not duplicate as much code for the reversed program. This works because the pound sign only starts a single line comment.

• When reversed, this does not produce the output reversed. – ATaco Sep 15 '17 at 0:34
• Seems to print a space and a newline at the TIO link you provided. – Jonathan Allan Sep 15 '17 at 3:59
• @JonathanAllan For some reason I thought 32 was a newline yesterday. Fixed to use 10 instead. – Poke Sep 15 '17 at 13:14
• Saved quite a few bytes from that :D – Jonathan Allan Sep 15 '17 at 13:15
• Combining this with Funky Computer Man's answer you can get to 30 bytes – Riley Sep 15 '17 at 13:39

# Excel VBA, 11 Bytes

(Ab)uses the fact that Excel has more than one STDOUT; Does not use Easy Mode

Anonymous VBE immediate window function that takes no input and outputs 12 to the VBE immediate window.

?12'12=]1A[


### Reversed

Anonymous VBE immediate window function that takes no input and outputs 21 to the the range [A1] on the ActiveSheet Object.

[A1]=21'21?


Note: ?12'12? works as well but feels a bit too close to palindromic to be within the spirit of the challenge

• shouldn't [A1] be reversed to [1A]? – J42161217 Sep 15 '17 at 0:24
• @Jenny_mathy Yep it should - and now it is – Taylor Scott Sep 15 '17 at 0:26

# Pyth, 4 bytes

"Jj"


Outputs Jj and jJ when reversed.

# Perl, 13 bytes

say+11#11 yas


And the reverse:

say 11#11+yas


Both print 11.

• They both print 11␤. It seems upon my reading of the rules that newlines should be included. So it should be print not say – Brad Gilbert b2gills Sep 15 '17 at 0:48
• You are right about the rules, but it would be better to replace the 11 with "^J" (where ^J stands for cntr-J, aka a new line (but a single byte)). We can then drop the space (or the +). The program then prints two new lines, and we will be using 14 bytes. – Abigail Sep 15 '17 at 14:36

# Mathematica, 5 bytes

44+55


or...

# Mathematica, 4 bytes

11*9


outputs 99

• The last one is no longer allowed. Quines are forbidden. – iBug Sep 15 '17 at 0:44
• @iBug I think you should try sandbox next time. I feel that you just wanted to post your answer without taking sometime to think about other peoples answers (like quines). Also it is not nice to change the rules after 12 answers have been posted... – J42161217 Sep 15 '17 at 0:49

# Python 2, 4342 52 bytes

### Source

#1.,"n\"tnirp:tpecxe
#"""
print"\n",\
1.#"""cexe:yrt


Try it online!

### Reversed source

try:exec"""#.1
\,"n\"tnirp
"""#
except:print"\n",.1#


Try it online!

Inspired by i cri everytim's answer. Does, however, not require 'easy mode'.

The program's outputs now are true reverses of one another, not ignoring the new line character. Thanks to @Jonathan Allan for pointing it out.

• @JonathanAllan Thanks for noticing. – Jonathan Frech Sep 15 '17 at 4:12

# Japt, 4 3 bytes

-1 byte thanks to @ETHproductions

### Normal

12C


Try it online! Prints 12.

### Reversed

C21


Try it online! Prints 21.

Only the last statement is printed, and C is the constant for 12.

• Don't think you even need the ;, do you? – ETHproductions Sep 15 '17 at 12:48
• @ETHproductions Right, I don't. I had been trying to implement using ; as the first char before coming to this one. – Justin Mariner Sep 15 '17 at 14:20

# Jelly, 3 bytes

1+³


Try it online!

This is 1 + 100 which is 101. The reverse is just 100 + 1 which is also 101. Replacing + with _ works too.

# Also 3 bytes

11»


Try it online!

The first is max(11, 0). The reverse is just max(0, 11). The argument is 0 by default if not present.

# Perl 5 / Perl 6 / Ruby, 17 bytes

print 12#12 tnirp


# Python 2, 20 bytes

print'\n';#'n\'tnirp


Try it online!

print'\n' prints both the single newline it instructs and an implicit newline after.

print'\n'; does exactly the same - the ; is just there to stop the program being a palindrome.

The # marks the start of a comment.

• 18 bytes if you return a number instead of a string -> if the implicit newline counts you could save even 2 more bytes from that answere. Or am I missing something? – Simon Sep 15 '17 at 7:45
• @Simon print 12; does not "return a number" it prints a string representation of the number. The implicit newline needs to be a part of the reversed output, so you'd need to print'\n'+12;#... – Jonathan Allan Sep 15 '17 at 7:59
• ...we could have print'';#''tnirp if it were not for the specification: "The output is at least 2 bytes long". – Jonathan Allan Sep 15 '17 at 8:01
• Okay, I did read that reverse specification wrong.Would print 1;#'1n\'tnirpwork? – Simon Sep 15 '17 at 11:22
• @Simon forwards that outputs 1\n and in reverse it outputs \n1\n. – Jonathan Allan Sep 15 '17 at 11:23

## Charcoal, 2 bytes

-¹


The - is simply a string literal that implicitly prints itself. The ¹ is a numeric literal, and the default is to implicitly print one - too. Any ASCII character and non-zero Unicode superscript would work.

²←


Forwards, this prints two -s, then moves the cursor back one step (but this does not affect the output). Backwards, this prints two -s leftwards, but the output remains the same. Any subscript from 2 to 9 would work here, as would a right arrow or the reflect operator ‖.

# 05AB1E, 4 bytes

?RA?


# Japt, 2 bytes

Both output 11. B is the Japt constant for 11 and the w method, when applied to a number, returns the larger of that number and any number passed to it as an argument.

wB


Try it

Bw


Try it

# Javascript (ES6), 12 bytes

_=>12//12>=_


Reversed:

_=>21//21>=_


Code snippet:

a=_=>12//12>=_
b=_=>21//21>=_
console.log(a())
console.log(b())

# Java 8, 132 bytes

Dang full program requirements..

interface M{static void main(String[]a){System.out.print("OK");}}//}};)"OK"(tnirp.tuo.metsyS{)a][gnirtS(niam diov citats{M ecafretni


Try it here. Prints OK.

Reversed:

interface M{static void main(String[]a){System.out.print("KO");}}//}};)"KO"(tnirp.tuo.metsyS{)a][gnirtS(niam diov citats{M ecafretni


Try it here. Prints KO.

• Hey! I said "make a note" if you're using the Easy Mode rule. – iBug Sep 16 '17 at 1:41
• @iBug Oops.. misread that part. Roll-backed to my initial version. I edited on purpose so it wasn't the easy mode anymore; but apparently I've edited into the easy mode instead.. My initial answer was already not the easy mode.. My bad. – Kevin Cruijssen Sep 16 '17 at 15:08

# Neim, 2 bytes

γδ


Outputs 12. Reversed, outputs 21.

Try it online!

# SmileBASIC, 4 bytes

?12?


This will work in many BASIC dialects.

Prints "12" forwards, and "21" backwards.

# brainfuck, 6723 21 bytes

• Saved two bytes thanks to 12Me21; using a tab instead of a new line.
+++++++++..+++++++++>

Try it online!

The program's ouput are two spaces new lines tabs. It is nearly a palindrome, apart from the trailing or leading cell shift (>).

• Using tab (character 9) would save 2 more bytes. – 12Me21 Mar 1 '18 at 19:28

# Triangular, 6 bytes

%.%%%%


Prints 000. Triangle looks like this:

  %
. %
% % %


Reversed triangle looks like this:

  %
% %
% . %


The IP starts travelling southeast from the topmost character, so in both triangles %%% is interpreted.

## Unix sh, 15 bytes

echo ab#ab ohce


Reversed:

echo ba#ba ohce


Outputs ab and ba, respectively.

# shortC, 18 bytes

AJ"hi")}//})"hi"JA


Prints hi. Exploits comments. Try it online!

# rk, 50 bytes

rk:start
dne:kr
print: "hi" :tnirp
trats:kr
rk:end


Reversed via this tool:

dne:kr
rk:start
print: "ih" :tnirp
rk:end
trats:kr


rk ignores everything before rk:start and rk:end. Of course, it ignores everything in the middle it doesn't understand anyway.

# Cubically 2.1, 5 bytes

%0%1%


Prints 09. Try it online! or Try it reversed!

The top (0-indexed) face is initialized to 0 and the left (1-indexed) face is initialized to 9. So printing (%) 0 prints 0 and printing 1 prints 9.

No longer works in Cubically 2.2 as % can be called implicitly.

# Implicit, 2 bytes

À\


Same as the winning RProgN 2 answer. Try it online!

## RProgN 2, 3 bytes

1
0


Output:

0
1


Try it online!

Reversed source:

0
1


Reversed output:

1
0


Try it online!

• at least give other people a chance to answer your challenge before you post your own answers – HyperNeutrino Sep 15 '17 at 0:04
• Is this the only thing anyone knows about RProgN2? It's a rather powerful language >:I – ATaco Sep 15 '17 at 0:37
• @ATaco Yes. Someone else posted this twice on my questions, so it's the only program I can write. – iBug Sep 15 '17 at 0:38
• Well it Has a tutorial if you ever feel like learning more about it! :P – ATaco Sep 15 '17 at 0:40