| Bytes | Lang | Time | Link |
|---|---|---|---|
| 009 | AWK | 250804T133829Z | xrs |
| 023 | Bespoke | 250804T111335Z | Josiah W |
| 005 | Vyxal | 230508T234957Z | emanresu |
| 003 | J | 191109T032310Z | Jonah |
| 003 | ><> Fish | 230508T134210Z | emirps |
| 002 | Dis | 221018T131919Z | 鳴神裁四点一号 |
| 002 | Brachylog | 221018T114638Z | Fatalize |
| 003 | Vyxal | 221018T113812Z | DialFros |
| 017 | 7 | 220626T110454Z | ais523 |
| 015 | Make | 220627T185130Z | cnamejj |
| 002 | Ly | 220627T072440Z | cnamejj |
| 001 | HBL | 220627T175118Z | DLosc |
| nan | Fig 0.1.0 | 220627T160311Z | Seggan |
| 106 | Python 3 | 191109T101519Z | user2357 |
| 001 | Halfwit | 220627T061433Z | emanresu |
| 031 | Whispers v3 | 210204T163513Z | Razetime |
| 002 | Actually | 201221T033445Z | PkmnQ |
| 004 | 33 | 201221T032414Z | TheOnlyM |
| 003 | AppleSoft Basic | 201220T235902Z | roblogic |
| nan | 201220T202537Z | Kamila S | |
| 002 | @ | 191125T052447Z | user8505 |
| 002 | GolfScript | 191125T035708Z | user8505 |
| 004 | Ahead | 191124T201123Z | snail_ |
| 014 | Java | 191111T225931Z | Okx |
| 2025 | Bitwise Cyclic Tag | 191114T034906Z | user8505 |
| 010 | SimpleTemplate | 191113T101219Z | Ismael M |
| 052 | Haskell | 191112T172728Z | OpenAI w |
| 004 | TIBASIC Nontrivial | 191111T200301Z | Feldspar |
| 012 | bash | 191110T013648Z | Feldspar |
| 020 | Whitespace | 191111T170623Z | Kevin Cr |
| 002 | Deadfish~ | 191111T165158Z | squid |
| 013 | Poetic | 191111T162433Z | JosiahRy |
| 003 | Triangular | 191111T153156Z | squid |
| 004 | SmileBASIC | 191111T142841Z | 12Me21 |
| 019 | JavaScript | 191109T013535Z | rydwolf |
| 003 | MarioLANG | 191111T091739Z | CoedRhyf |
| 012 | HolyC | 191110T192339Z | Roninkoi |
| 002 | Rebol | 191110T101624Z | Bent For |
| 003 | POSIX sh Dash | 191110T100537Z | GammaFun |
| 002 | R | 191109T235415Z | AkselA |
| 003 | Runic Enchantments | 191110T012903Z | Draco18s |
| 019 | Turing Machine Code | 191109T155519Z | ouflak |
| 010 | Wolfram Language Mathematica | 191109T202031Z | att |
| 002 | Befunge98 PyFunge | 191109T185018Z | The Fift |
| 021 | C gcc | 191109T183906Z | S.S. Ann |
| 002 | Jelly | 191108T232049Z | hyperneu |
| 002 | Actually | 191109T041402Z | user8505 |
| 002 | MathGolf | 191109T125942Z | user8505 |
| 032 | Wren | 191109T035800Z | user8505 |
| 020 | Ceylon Snippet | 191109T122832Z | Paŭlo Eb |
| 002 | PHP | 191109T111258Z | Night2 |
| 002 | Japt | 191109T100831Z | AZTECCO |
| 006 | Ruby | 191109T103313Z | Neil Sla |
| 011 | Perl 5 | 191109T073529Z | Xcali |
| 002 | brainf*** | 191109T061748Z | HiddenBa |
| 002 | 05AB1E | 191109T035915Z | user8505 |
| 002 | Japt | 191109T032748Z | Gymhgy |
| 002 | Pyth | 191108T233048Z | frank |
| 017 | Python 3 | 191108T233248Z | hyperneu |
| 002 | Keg | 191108T233040Z | lyxal |
AWK, 9 bytes
$0=1#2=0$
Something more substantial:
AWK, 23 bytes
END{print(2^1)tnirp}DNE
Works because AWK will assume tnirp and DNE are empty variables.
Bespoke, 23 bytes
Forwards
won O.K drawer-on a ram
Outputs ASCII 1 (SOH). Equivalent to PUT X:I;OUTPUT CH;H LDV.
Backwards
mar a no-reward K.O now
Outputs the number 2. Equivalent to PUT X:BI;OUTPUT N;H LDV.
Vyxal, 4 bits1, 0.5 bytes
2
Try it Online! (link is to bitstring) The bitstring form of this is 0101, which translates to 2.
Reversed - Try it Online! (outputs 0)
If we stretch the rules a bit, we can get two bits: Try it Online! !enilnO ti yrT, which respectively output an empty string and 0 - 0 and 1 in unary.
J, 3 bytes
1"_
one or infinity...
1"_is the constant 1, turned into a verb of rank"infinity_. Hence always returns 1._"1is the constant infinity_, turned into a verb of rank1. Hence always returns infinity.
Brachylog, 2 bytes
+1
There are probably loads of different 2 byte answers.
Explanation
+1 states that 1 is the result of the sum of an unknown list of integers, which is obviously true. (there are infinitely such lists).
1+ states that we can sum the list 1 into some result, which is obviously false. since 1 isn’t a list.
Vyxal, 3 bytes
2-1
Running it forward gives 1, running it backwards gives 2.
This because vyxal's syntax is weird:
ab- (vyxal) = a-b (py)
7, 2 characters, 1 byte in 7's encoding
31
This should be the first valid 1-byte solution (because the existing 1-byte solution in BCT requires a particular value on its input to work, and isn't counting it in the byte count – that could only be assumed in a full program, and BCT full programs can't do I/O and must wipe all their working memory to be able to halt, thus have no way to halt with a value). 7's encoding packs multiple characters into a single byte: here are xxd hexdumps for the forward and reverse programs:
00000000: 67 g
00000000: 2f /
This conceptually outputs a string: 31 for the forwards program, and an empty string for the backwards program. The output encoding is set to be the same as the input encoding; so if you encode the program in 7's encoding, you'll get a single byte of output which encodes the string 31 (and if you use ASCII instead, you'll get two bytes that encode the string 31 in ASCII).
Explanation
On the first pass through the program, the 3 appends a "print and pop" command to the stack, and the 1 appends a "push empty stack element" command to the stack. So, we end up forming a program on top of the stack. At the end of the first pass through the program, 7 will run the resulting program, but without popping it from the stack.
With the forward version of the program, the "print and pop" command will attempt to print the program consisting of a "print" command and a "pop" command. That isn't a valid literal, so the 7 interpreter will construct code that's capable of constructing that stack element and print that instead; in this case, the code it finds for for "push a stack element that generates a 'print and pop' command then a 'push empty stack element command'" is 731 (i.e. basically the program we wrote, although our program appends to an implicit empty stack element, whereas the reconstructed program makes a new one). The print routine interprets the 7 as a command to set the output encoding to the same encoding that was used for the source code, and then the 31 is interpreted as a literal and gets printed. The command in question pops two things in total (the thing it's printing and the element below), so the stack now contains no data and thus there are no more passes through the program; it just exits (even though we push an empty stack element after this point, those don't affect the end-of-program behaviour).
With the reverse program, we're pushing the empty stack element before the print attempt, rather than the other way round, so it's now an empty string that gets printed, and the remnants of the program (which are below it) get popped without printing them. Everything is now the same as in the forward program, so the reverse program also exits naturally and without error.
Make, 14 15 bytes
x:#
#$@$#
#:y
Updated to add a trailing tab on the second line...
Here's another one that's not as short, but seems interesting enough to post...
Forwards it prints x and backwards it prints y. It works by referencing the $@ symbol, which is defined as the target being made. The "command" run is just a comment to the shell, so it's a no-op. But by default Make echos the commands it runs.
Also, the $# reference doesn't cause an error, and evaluates to an empty string, which allows #$@$# to work both directions without having to add more characters.
Ly, 2 bytes
-`
Forwards outputs 1 and backwards shows -1.
Why? Forwards:
- : subtract top two stack entries, when empty produces "0"
` : increment top of stack, produces "1"
Backwards:
` : increment top of stack, when empty produces "0"
- : subtract top two stack entries, produces "-1"
HBL, 1 byte
+2
Run forwards, outputs 3:
+ Increment
2 Two
Run backwards, outputs 8:
2 Double
+ Four
In fact, any program consisting of two characters from the set 2<+-/% will work. Here are all the possible combinations together with their outputs. We could also add 0 to the set if it weren't for the "same data type" restriction.
Fig 0.1.0, \$2\log_{256}(96)\approx\$ 1.646 bytes
,"
See the README to see how to run this
Argh. Beaten by Halfwit by more than half a byte. In the forward position, it prints a single newline. Backwards, ",, it prints a comma followed by a newline.
Python 3, no comments or string literals, 106 bytes
x=quit
y=x.__class__
y.__add__=print
y.__pos__=x
x+x++x+x
x=__sop__.y
tnirp=__dda__.y
__ssalc__.x=y
tixe=x
I've never liked how comments and string literals let you "turn off" most of your language's syntax in challenges like this, so I wanted to see how far I could golf things without using either comments or string literals. This is what I came up with.
Since I don't have any way to disable the syntactical significance of parentheses, I cannot use the function call operator. Any attempt to do so would result in the reversed code having a closing parenthesis before the first opening parenthesis, which is invalid outside a comment or string literal. I also can't use def or container literals (aside from unparenthesized tuples), and my access to language features is in general extremely restricted.
One thing I can do is take advantage of Python's operator overloading to call functions implicitly. My ability to define any classes or functions is extremely limited, but fortunately, there are enough tools lying around in the built-in namespace for me to use. Most built-ins don't let me perform the attribute assignment I need to redefine their operator overloads, but (unless Python is run with one of the flags that disables site importing) the auto-imported site module adds quit and exit objects to the built-ins. These objects are instances of non-C classes, so I can reassign their operator overloads.
Setting __add__ to print lets me use addition to print things, and setting __pos__ to quit or exit lets me use the unary + operator to abort the program before the rest of the code runs. Without setting __pos__, I would need a bunch of additional code to make sure the "backwards" part of the code can find all the variables and attributes it needs to not fail. With __pos__, I only need to make sure the "backwards" code is still syntactically valid.
Forward, the code prints
Use quit() or Ctrl-D (i.e. EOF) to exit
Backward, the code prints
Use exit() or Ctrl-D (i.e. EOF) to exit
(The messages are slightly different on Windows. For platform-independent output at the expense of 3 extra bytes, you can replace the middle line with x+1++x++2+x, printing 1 when run forwards and 2 when run backwards.)
I also tried to figure out a way to do this by defining my own class instead of messing with quit.__class__. I got as far as the following:
if.1j:adbmal=1j
class ton:adbmal
a=lambda:j1.fi
j1=a
a.__dict__=a.__globals__
class ton:adbmal is one of the very few combinations of class name and class body such that the class statement is syntactically valid backward. tressa, led, labolg, tropmi, and esiar would also have been valid class names (with a different class body, such as not fi), but ton is the only one where the reversed name can be part of an expression, giving the most flexibility.
if.1j:adbmal=1j assigns a value to adbmal to make the class body succeed, while still being syntactically valid backward.
The stuff with a and j1 lets me use j1.ton to refer to my ton class, which is still a valid expression backward.
At this point, I got stuck. I couldn't figure out how to get my class out of j1.ton and into a more useful variable. I can't assign attributes on j1.ton and still have valid syntax backward, so I can't set operator overloads. I also wanted to set builtins.__build_class__ to my class so I could abuse the class statement to construct instances without the function call operator, but trying to put j1.ton on the right side of an assignment produces invalid syntax backward.
If I had been able to name my class something like fi or tpecxe, I could have used tricks like b:j1.fi to get the class into an annotation and then a.__dict__=__annotations__ to get it into a.b, but I couldn't find any way to get the class statement and the annotation tricks to hook up. Anything that was compatible with the class statement was incompatible with the annotation tricks.
(You might wonder why I didn't abuse builtins.__build_class__ to call an existing function directly, like print. I couldn't figure out a way to do that and have the output be deterministic, and I wanted deterministic output.)
Halfwit, 1 byte
*k
The second valid one-byte solution :P
* is multiplication, multiplying two 0s. k is a digraph character, and on its own a NOP, but k* is exponentiation.
Alternatively, anything that's a single char before > works as > delimits a compressed integer, so >x will push some number, and x> will apply x then push 0.
Whispers v3, 31 bytes
1 tuptuO >>
> 1
>> Output 1
0 >
Try it online!, !enilnO tI yrT
Hooray for strict parsing rules!
The first and last lines are ignored, because they don't fit the right syntax. They come into action when reversed.
Dyalog APL
Boring solution using comments
0⍝1 => 0
1⍝0 => 1
Even more boring numeric solution:
10 => 10
01 => 1
Basic arithmetics:
2-1 => 1
1-2 => ¯1
@, 2 bytes
Outputs \n1, where \n represents a literal newline.
\1
Reversed
Returns 1, the expression after 1 is ignored.
1\
GolfScript, 2 bytes
Simply prints 1 because the duplicate instruction duplicates the null string.
.1
Reversed
Outputs 11 because that is the value 1 duplicated.
1.
GolfScript, 4 bytes
Outputs 0 because 1 - 1 is 0.
1 1-
Reversed
Outputs -11 due to concatenation.
-1 1
GolfScript, 2 bytes (Am I allowed to use the null string?)
Outputs the null string, because the null string from the input minus 1 is still the null string.
1-
Reversed:
Pushes -1 onto the stack.
-1
Ahead, 4 bytes
O@j1
Prints 0 forward and 1 backward.
Forward
O pop stack and print number
@ end
j1 not reached
Backward
1 push 1
j jump next cell
O pop stack and print number
@ end
Control flow is more interesting backward because I tried to reduce the amount of redundant characters.
Java, 14 bytes
()->1;//;0>-)(
Simple function that uses comments to exclude the other part. Outputs 1, and reversed outputs 0.
Bitwise Cyclic Tag, 2 bits (0.25 bytes)
With an input of 1 this should either set the data string to a null string or a string of length 2 in its next iteration.
01
Explanation:
0 Delete the leftmost data bit.
Halt. No more instructions executed.
1 Not executed
Reversed:
1 If the left-most data-bit is 1,
0 Append a 0 to the data-string.
SimpleTemplate, 10 bytes
This was actually hard to optimize, without going into the trivial answer.
{@echo"1"}
Outputs the string "1".
When reversing, you get the following:
}"1"ohce@{
Outputs the string }"1"ohce@{.
As stated in the question: "The output can be any two distinct values, of the same data type.", and both solutions output a distinct string.
You can test this on http://sandbox.onlinephpfunctions.com/code/ec4bf4b3efa93c63c6c5c9f1458330da0178b6cd
(On line 960, change between the $code and $reversed variables)
SimpleTemplate, 2 bytes
This one is extremelly trivial:
<any 2 different bytes>
Reversing them will output whatever is reversed.
Haskell, 52 bytes
a=0--
--b tnirp=b#a
niam=main
1#a=niam
main=print a
==> prints "1"
a tnirp=niam
main=a#1
niam=main
a#b=print b--
--0=a
==> prints "0"
Explanation:
a=0--
-- FWD: define constant "a" to be 0 / BWD: No-op --
--b tnirp=b#a
-- FWD: No-op / BWD: define a function "#" in two arguments and prints the --
-- second --
niam=main
-- FWD & BWD: define constant "niam" to be the same as "main" --
1#a=niam
-- FWD: define a function "#" in two arguments that produces "main" if the first --
-- argument is 1 / BWD: define constant "main" to be the result of the function --
-- "#" applied to the arguments "a" and 1 --
main=print a
-- FWD: define constant "main" to be an IO action that prints the value of "a" / --
-- BWD: define a function "a" in one argument that always produces the value --
-- of "niam" --
Of course, there is also the shorter item:
Haskell, 29 bytes
main=print 1--
--0 tnirp=niam
which is much less interesting.
TI-BASIC Non-trivial, 4 5 bytes
Disp "Disp :
This outputs 'Disp :'
Since TI-BASIC is token based, reversing it gives
:Disp "Disp
which outputs 'Disp'
Let me explain. 'Disp ' is one token which prints the given string to the home screen. First we are giving it a string of 'Disp :', so simple there. When reversed, since each 'Disp ' is one byte, we get the reversed code above. This reversed code starts with a ':', which ends the line, and means nothing here. The remaining code is 'Disp "Disp ', which runs and outputs 'Disp ' to the home screen.
TI-BASIC Trivial, 2 bytes
If a program ends with a values, then it outputs it. This lets us do
12
which outputs 12, and reversed is
21
which outputs 21.
bash, 12 bytes (no comments or string literals)
echo 0$ ohce
Prints "0$ ohce"
echo $0 ohce
Prints "bash ohce"
bash, 11 bytes (no comments or string literals)
echo ftnirp
Prints "ftnirp"
printf ohce
Prints "ohce"
Whitespace, 20 bytes
S S S N
T N
S T N
N
N
T S N
T N
T T S S
Letters S (space), T (tab), and N (new-line) added as highlighting only.
Outputs 0/-1.
Try it online or try it online reversed (with raw spaces, tabs and new-lines only).
Explanation:
Very minor modification of my answer here (outputting 0 is 1 byte shorter than 1), so I'm just gonna copy-paste the explanation:
Utilizing the Exit Program builtin being a short palindrome NNN (also note that without an exit, every Whitespace program would result in an error, making it invalid for this challenge).
The regular program will:
SSSN # Push 0 to the stack
TNST # Pop and print the top of the stack as number
NNN # Exit the program, making everything after it no-ops
The reverse program will:
SSTTN # Push -1 to the stack
TNST # Pop and print the top of the stack as number
NNN # Exit the program, making everything after it no-ops
Small additional explanation of pushing a number:
- First
S: Enable Stack Manipulation - Second
S: Push a number to the stack SorT: Positive/negative respectively- Some
S/Tfollowed by a trailingN: number in binary, whereS=0andT=1
I.e. SSTTSTSN pushes -10. Only the first three and trailing N are mandatory, so SSSN/SSTN will both push 0.
Poetic, 15 13 bytes
tis,A NAMETAG
Prints ASCII character 1 (SOH).
GATEMAN A,sit
Prints ASCII character 0 (NUL).
The previous answer ends with an "Unexpected EOF" error forwards because the END command (any ten-letter word) is omitted, and a "Mismatched IF/EIF" error backwards because EOF is encountered before an IF/EIF loop can end. The following answer terminates properly.
Poetic, 51 bytes
the difference between I and certain ridiculous men
Prints a newline.
nem suolucidir niatrec dna I neewteb ecnereffid eht
Prints a newline and a "vertical tab" character.
(I really wanted to be able to make the programs make sense both backwards and forwards, but I'm not sure that's possible in English, and I don't know any other languages to try that out with.)
Triangular, 3 bytes
i.%
Prints 1.
%.i prints 0.
If it weren't invalid to do an integer and a character, %# would've been a nice 2-byter.
SmileBASIC, 4 bytes
?12?
prints 12\n\n forwards and 21\n\n backwards
JavaScript, 19 bytes
Returns true because of the assignment at the end, since JS treats that as defining a global variable. The first part is an arrow function, which is ignored. When run backwards, eurt is set to NaN (not a number), and since NaN is not greater than true (or equal), it returns false.
eurt=>true;NaN=true
eurt=NaN;eurt>=true
JavaScript, 3 bytes
A snippet which outputs 1, or -1 in reverse. Very simple.
2-1
1-2
JavaScript, 7 bytes
Abuses the not equal to operator and the not operator, will output false, or true in reverse. JavaScript uses NaN as not-a-number.
5==!NaN
NaN!==5
JavaScript, 18 bytes
Another boring solution, with comments instead of subtraction. Returns 1, or 2 in reverse. I included the print statements in these.
print(1)//)2(tnirp
print(2)//)1(tnirp
JavaScript, 7 bytes
Similar to the previous answer, but with assignment instead of equal-to. Uses the atob variable, which is a builtin in browser Javascript (decodes base64). Since TIO doesn't include browser builtins, I defined it just to keep it from erroring. Works as expected in console. Return true, or false in reverse.
2!=atob
bota=!2
MarioLANG, 3 bytes
:
+
Prints 0
+
:
Prints 1
MarioLANG, 10 bytes
==
:+
==
Prints 0
==
+:
==
Prints 1
HolyC, 12 bytes
Like the C version, except using the implicit print in HolyC
"0"; // ;"1"
Prints 0
"1"; // ;"0"
Prints 1
Spaces required by the compiler :)
Rebol, 2 bytes
#1
Prints #1
1#
Prints ##
POSIX sh (Dash, Bash, Zsh, ...), 3 bytes
: !
The builtin : discards its arguments and exits 0 (true). Reversed, ! negates the exit code of : and exits 1 (false).
R, 2 bytes
.1
Prints 0.1.
1.
Prints 1.
Both numeric (double).
Less trivial? and for an explicit true/false
2>1
# TRUE
1>2
# FALSE
Runic Enchantments, 3 bytes
0@1
Prints 0 forwards and 1 backwards.
If no output is allowed, then @1 saves a byte.
Turing Machine Code, no comments or string literals, 19 bytes
0 * 0 * 0
0 * 1 * 0
Reversed:
0 * 1 * 0
0 * 0 * 0
The code runs without errors, but does loop forever. Prints '0' forward, prints '1' reversed.
Jelly, 2 bytes
+1
Prints 1.
Jelly, 2 bytes
1+
Prints 2.
The reason for this is that Jelly's dyad-nilad structure chains differently on either side. +1 becomes a monad meaning "plus one", which is applied to the Left Argument, which defaults to zero. 1+ does not become a monadic chain here (if I remember correctly - correct me if my Jelly theory is off; I'm a bit rusty on the structural component), but rather is seen as 1 set as the Left Argument, and then + is applied as a dyad to (left, left) in the default case of no Right Argument, giving 1 + 1.
Great challenge; I almost feel like this is a cheese. I don't know if I should be happy with this solution or feel bad for having such a short and trivial solution >_<.
This uses Jelly's structure to be fancy. A more boring answer would just be 01 (prints 1) and 10 (prints 10), or any other two-digit number and its reverse (that isn't a palindrome).
Actually, 2 bytes
Decrement empty value & push 1.
D1
Reversed program decrements 1, outputting 0.
1D
05AB1E, 2 bytes
The exact same answer ported to a different language.
<1
MathGolf, 2 bytes
This one does not have any nilads or dyads inside the program. Just monads.
±(
Explanation
± Find absolute value of the implicit 0
( Decrement 0, resulting -1.
Reversed:
( Decrement 0, resulting -1.
± Find absolute value of -1, which results in 1.
Ceylon (Snippet), 20
The same trivial thing as in many other languages:
print(1);//;)2(tnirp
Outputs 1.
print(2);//;)1(tnirp
Outputs 2.
Given that parentheses need to be in the right order and you need print for output, I don't think this can be improved.
A full program or function needs even more braces/parentheses mirrored, so no chance of getting it better.
Ceylon (anonymous function), 17
If we don't need to output anything, but just return it from an anonymous function, then this is enough:
()=>//
1.2
//>=)(
A function which returns 1.2 (a floating point value).
()=>//
2.1
//>=)(
A function which returns 2.1 (a floating point value).
Ceylon (expression with return value), 3
If we accept just an expression (which then can be printed), then we don't even need any comments:
2.1
Gives 2.1 (a floating point value).
1.2
Gives 1.2 (a floating point value).
PHP, 2 bytes
12
Prints 12 ...
21
Prints 21 ...
Looking for non-trivial solution?
PHP, 11 bytes
<?=1;#;2=?<
Prints 1 ...
<?=2;#;1=?<
Prints 2 ...
Don't like comment abuse?
PHP, 13 bytes
;echo+1-ohce;
Prints 1 ...
;echo-1+ohce;
Prints -1 ...
Note: this one is an exact copy of my answer here: https://codegolf.stackexchange.com/a/193169
Japt, 2 bytes
c1
Return x rounded up to nearest multiple of N => output 0
1c
x default to 1 => output 1
Ruby, 6 bytes
p:stup
Output
:stup
Reversed output
p
Perl 5, 11 bytes
say$-,$$yas
Outputs 0 when run forward. Outputs the current process number followed by 0 when run backwards.
05AB1E, 2 bytes
Push 1 onto the stack & negates. (This results in -1)
1(
Negate empty value & push 1. Output 1 implicitly.
(1
Japt, 2 bytes
1g
Returns 1. Reverse returns -1.
g is the sign function when it has no arguments, and returns the sign of the argument minus the caller if called with an argument. So g1 would be the sign of zero minus one because the default input is 0
Pyth, 2 bytes
\"
Returns the string ' " ' (one set of double quotes)
Pyth, 2 bytes
"\
Returns "\"
Oops, my earlier answer missed that they had to be the same data type. This answer returns two different strings, and relies on the fact that '\' makes a one character string of the input and that Pyth closes strings implicitly
Python 3, 17 bytes
print(1)#)2(tnirp
I promise this is the last trivial/cheese one I post; I'm trying to think of a more interesting solution. If I remember I'll see where I can get with this.
Keg, 2 bytes
10
Keg, 2 bytes
01
When run forwards, it prints 10. When run backwards, it prints 01.
I might try to create a non-trivial answer soon, as this seems like a really great challenge!