[Question]
  [
Your task is simple, write a single code snippet that when executed in one language outputs only the string `'abc'` and when executed in another language outputs only the string `'cba'`. The program should take no input.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge.
  
[Answer]
# MATLAB / Octave, 41 bytes
```
disp(flip('abc',size(randsample(2,2),2)))
```
In MATLAB `randsample(2,2)` gives a 2×1 vector, so `size(...,2)` is `1`. Thus `flip` is applied along the first dimension, which is a singleton, so the original string `'abc'` is displayed:
[![enter image description here](https://i.stack.imgur.com/WDtXr.gif)](https://i.stack.imgur.com/WDtXr.gif)
In Octave `randsample(2,2)` gives a 1×2 vector, so `size(...,2)` is `2`. Thus `flip` is applied along the second dimension, that is, the string is flipped from left to right:
[![enter image description here](https://i.stack.imgur.com/I9I05.gif)](https://i.stack.imgur.com/I9I05.gif)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E) / [Pyth](https://github.com/isaacg1/pyth), 5 bytes
```
_"abc
```
**[Try 05AB1E online!](https://tio.run/##MzBNTDJM/f8/XikxKfn/fwA "05AB1E – Try It Online")**
**[Try Pyth online!](https://tio.run/##K6gsyfj/P14pMSn5/38A "Pyth – Try It Online")**
**[This also works in Pyke, outputting `cba`.](https://tio.run/##K6jMTv3/P14pMSn5/38A)**
**[This also works in Recursiva, outputting `cba`.](https://tio.run/##K0pNLi0qzixL/P8/XikxKfn/fwA)**
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php) and [Bash](https://www.gnu.org/software/bash/), 57 bytes
```
   		    	
 
 	
     	
	    
 	
     	
	   	
echo  cba
```
[Try it online!](https://tio.run/##K8/ILEktLkhMTv3/X0FBgZNTAURyKXCBCAgbLITG5@RKTc7IV1BITkrk4uL6/x8A "Whitespace – Try It Online")
[Answer]
# 25 bytes
```
print(1/2and'cba'or'abc')
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69Ew1DfKDEvRT05KVE9v0g9MSlZXfP/fwA "Python 2 – Try It Online") ([Python 2](https://docs.python.org/2/))
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69Ew1DfKDEvRT05KVE9v0g9MSlZXfP/fwA "Python 3 – Try It Online") ([Python 3](https://docs.python.org/3/))
[Answer]
# Vim / Notepad.exe, 10 bytes
```
cbaabc<esc><backspace><backspace><backspace>
```
[Answer]
-1 byte if I make `==0` into `>0` but that's already another answer
# [Python 2](https://docs.python.org/2/), 26 bytes
```
print('acbbca'[1/2==0::2])
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EQz0xOSkpOVE92lDfyNbWwMrKKFbz/38A "Python 2 – Try It Online")
---
# [Python 3](https://docs.python.org/3/), 26 bytes
```
print('acbbca'[1/2==0::2])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQz0xOSkpOVE92lDfyNbWwMrKKFbz/38A "Python 3 – Try It Online")
`1/2` gives `0` (floordiv) in Python 2 and `0.5` (truediv) in Python 3. Thus, `1/2==0` gives 1 in Python 3 and 0 in Python 2 (actually, booleans, but those are just integers), so `'acbbca'[1::2] => 'cba'` is given for Python 3 and `'acbbca'[0::2] => 'abc'` is given for Python 2.
[Answer]
# Excel / Google Sheets, ~~41~~ ~~28~~ ~~27~~ 24 Bytes
Anonymous worksheet formula that takes no input and outputs `"ABC"` to the calling cell in Excel and `"CBA"` to the calling cell in Google Sheets
```
=IfError(M("CBA"),"ABC")
```
In Google Sheets, `M(...)` is an alias for and autoformatted to `T(...)` (short for `Text()`). This call returns the text value of the passed variable, `"CBA"`. `"CBA"` is not caught as an error, so `"CBA"` is returned by `IfError(...,"ABC")`
In Excel, there is no `M(...)` function, and `M(...)` is not an alias and therefore `M("CBA")` returns the formula not found error, `#NAME?`. This is caught by `IfError(...,"ABC")`, which in turn returns `"ABC"`.
---
## Previous Versions, 27, 28, 41 Bytes
See edits for explanations
```
=If(IsErr(A()),"ABC","CBA")
```
```
=If(IsErr(GT()),"ABC","CBA")
```
```
=IfError(If(Info("NUMFILE"),"ABC"),"CBA")
```
[Answer]
# [CJam](https://sourceforge.net/projects/cjam/) / [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
"abc"R
```
Try it online:
* [CJam](https://tio.run/##S85KzP3/XykxKVkp6P9/AA);
* [05AB1E](https://tio.run/##MzBNTDJM/f9fKTEpWSno/38A).
### How it works in CJam
```
"abc"    Push this string
R        Push variable R, predefined to the empty string
         Implicitly display stack
```
### How it works in 05AB1E
```
"abc"    Push this string
R        Reverse
         Implicitly display top of the stack
```
[Answer]
With apologies to @HyperNeutrino for stealing most of his answer (I don't have the reputation to comment yet)
# [Python 2](https://docs.python.org/2/), 25 bytes
```
print('acbbca'[1/2>0::2])
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EQz0xOSkpOVE92lDfyM7AysooVvP/fwA "Python 2 – Try It Online")
# [Python 3](https://docs.python.org/3/), 25 bytes
```
print('acbbca'[1/2>0::2])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQz0xOSkpOVE92lDfyM7AysooVvP/fwA "Python 3 – Try It Online")
[Answer]
# JavaScript (NodeJS) and PHP, 46 bytes
```
<!--
strrev=console.log//--><?=
strrev("abc");
```
Prints `abc` in JS and `cba` in PHP.
[Try the JS online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f/fRlFXl6u4pKgotcw2OT@vOD8nVS8nP11fX1fXzsbeFiqloZSYlKykaf3/PwA)
[Try the PHP online!](https://tio.run/##K8go@P/fRlFXl6u4pKgotcw2OT@vOD8nVS8nP11fX1fXzsbeFiqloZSYlKykaf3/PwA) (note that TIO doesn't hide the HTML comments (`<!--`...`-->`)
[Answer]
# [Python 2](https://docs.python.org/2/) and Python 3, 42 bytes
```
try:exec("print'abc'")
except:print('cba')
```
[Try it online! (Python 2)](https://tio.run/##K6gsycjPM/r/v6So0iq1IjVZQ6mgKDOvRD0xKVldSZMrtSI5taDECiymoZ6clKiu@f8/AA "Python 2 – Try It Online")
[Try it online! (Python 3)](https://tio.run/##K6gsycjPM/7/v6So0iq1IjVZQ6mgKDOvRD0xKVldSZMrtSI5taDECiymoZ6clKiu@f8/AA "Python 3 – Try It Online")
Thought I'd try something different...
[Answer]
# Excel/Google Sheets, 28 bytes
Inspired by @TaylorScott, who used a function that only exists in Excel, I found an even shorter function that only exists in Google Sheets. Conveniently, it is designed to return strings:
```
=iferror(join(,"cba"),"abc")
```
**How it works**
In Google Sheets, `join([arg1], arg2, arg3,...argk)` will concatenate *arg2* -> *argk*, optionally using the separator specified in *arg1*. In this case, it successfully returns "cba."
Excel has no `join` function, so `iferror` sees a problem and returns "abc"
[Answer]
# Python / Befunge, ~~20~~ 18 bytes
*2 bytes saved thanks to @karhell*
```
print("abc")# ,,,@
```
[Try it online! for Python](https://tio.run/##K6gsycjPM/7/v6AoM69EQykxKVlJU1lBR0fH4f9/AA)
Python sees `print("abc")` then a comment.
[Try it online! for Befunge](https://tio.run/##S0pNK81LT/3/v6AoM69EQykxKVlJU1lBR0fH4f9/AA)
Befunge, removing all nops and useless commands sees `"abc",,,@` which puts `a`, `b` and `c` on the stack and then prints them (last in - first out).
[Answer]
# Python 2 / Python 3, 28 bytes
```
print('abc'[::int(1/2*4)-1])
```
In Python 2 `int(1/2*4)-1` evaluates to `-1` and so prints `cba`. - [TiO](https://tio.run/##K6gsycjPM/r/v6AoM69EQz0xKVk92soKxDbUN9Iy0dQ1jNX8/x8A)
In Python 3 it evaluates `1` so prints `abc`. - [TiO](https://tio.run/##K6gsycjPM/7/v6AoM69EQz0xKVk92soKxDbUN9Iy0dQ1jNX8/x8A)
[Answer]
# [R](https://www.r-project.org/)/[Cubix](https://github.com/ETHproductions/cubix), 20 bytes
```
cat("abc")#u@o;o;o(;
```
[R - Try it online!](https://tio.run/##K/r/PzmxREMpMSlZSVO51CHfGgg1rP//BwA "R – Try It Online")
[Cubix - Try it online!](https://tio.run/##Sy5Nyqz4/z85sURDKTEpWUlTudQh3xoINaz//wcA "Cubix – Try It Online")
For R, `cat("abc")` then shameless abuse of comments.
For Cubix
```
    c a
    t (
" a b c " ) # u
@ o ; o ; o ( ;
    . .
    . .
```
* `"abc"` Pushs a, b ad c onto the stack
* `)#` Increment the c, pushs number of element in stack
* `u` U-turn to the right
* `;(` Remove the count, Decrement the c
* `o;o;o@` Output cba and exit
Pushs the number on in stack
[Answer]
# [CJam](https://sourceforge.net/p/cjam) and [Gaia](https://github.com/splcurran/Gaia), 8 bytes
```
'c'b'a]$
```
[Try it in CJam!](https://tio.run/##S85KzP3/Xz1ZPUk9MVbl/38A "CJam – Try It Online")
[Try it in Gaia!](https://tio.run/##S0/MTPz/Xz1ZPUk9MVbl/38A "Gaia – Try It Online")
### Explanation
In both languages this defines a list of characters.
In CJam, `$` is sort, so it becomes `abc`.
In Gaia, `$` joins the list into one string, giving `cba`.
[Answer]
# Java 8 & C, 95 bytes
```
//\
interface a{static void main(String[]s){System.out.print("abc"/*
main(){{puts("cba"/**/);}}
```
[Try it in Java 8 - resulting in "abc".](https://tio.run/##HcpBCoAgEADAe68QTxqUD@gZHavDZhZrpJJbEOLbLboOY@GGxgfj7LKXotRYoSNzrqANgxQJCDW7PS7sAHSipxPdNkxRpv6JZI7WX9SGD0lwmDVXdfVHmVK4KAquZ/iwVrLLuZQX)  
[Try it in C - resulting in "cba".](https://tio.run/##HcpBCoAgEADAe68QTxqUD@gZHqvDupkslEVuQUhvt@g6DDa4QAylGDNUFNkfM6AXkBMDE4pro0msQFFZPiiGfkw62zuxX9vt5Hb/kJUEh9LU1R91zvvJSUl08GFtdPc8pbw)
**Explanation:**
```
//\
interface a{static void main(String[]s){System.out.print("abc"/*
main(){{puts("cba"/**/);}}
```
As you can see in the Java-highlighted code above, the first line is a comment due to `//`, and the C-code is a comment due to `/* ... */`, resulting in:
```
interface a{static void main(String[]s){System.out.print("abc");}}
```
---
```
//\
interface a{static void main(String[]s){System.out.print("abc"/*
main(){{puts("cba"/**/);}}
```
Not sure how to correctly enable C-highlighting, because `lang-c` results in the same highlighting as Java.. But `//\` will comment out the next line, which is the Java-code, resulting in:
```
main(){{puts("cba");}}
```
[Answer]
# C and C++, ~~115~~, ~~78~~, ~~58~~, 56 bytes
```
#include<stdio.h>
main(){puts(sizeof('x')>1?"abc":"cba");}
```
78 bytes, thanks to [challenger5](https://codegolf.stackexchange.com/users/61384/challenger5).
58 bytes, thanks to [aschepler](https://codegolf.stackexchange.com/users/18653/aschepler).
56 bytes, thanks to [hvd](https://codegolf.stackexchange.com/users/16385/hvd)
[Try it - C++!](https://tio.run/##Sy4o0E1PTv7/XzkzLzmnNCXVprgkJTNfL8OOKzcxM09Ds7qgtKRYozizKjU/Tb1C3c7QXikxKVnJSik5KVFJ07r2/38A "C++ (gcc) – Try It Online")
[Try it - C!](https://tio.run/##S9ZNT07@/185My85pzQl1aa4JCUzXy/Djis3MTNPQ7O6oLSkWKM4syo1P029Qt3O0F4pMSlZyUopOSlRSdO69v9/AA "C (gcc) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) 2.0/JavaScript, ~~11~~ 10 bytes
```
"abc"
//Uw
```
[Japt 2.0](https://ethproductions.github.io/japt/?v=2.0a0&code=ImFiYyIKLy9Vdw==&input=) outputs `cba`
[JavaScript](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@18pMSlZiUtfP7T8f3J@XnF@TqpeTn66RprmfwA) outputs `abc`
[Answer]
# [Vyxal/Hexagony](https://github.com/Lyxal/Vyxal), 19 bytes
```
ka3wiṘ,Qλa;b@;<λ;c/
```
[Try it Online! (Vyxal)](https://lyxal.pythonanywhere.com?flags=&code=ka3wi%E1%B9%98%2CQ%CE%BBa%3Bb%40%3B%3C%CE%BB%3Bc%2F&inputs=&header=&footer=)
[Try it Online! (Hexagony)](https://hexagony.net/#lzN4Igxg9gJgpiBcIDWBDAzAdwJaA08ANAIqDdwCgNwBGAAqQDxGlgD0IeIWAdgA4CuALgiACMAJjQAWAKwA2AOwAOAJws2XPgFlocRCgBOAcxABfIA===)
The program is split into two main parts, `ka3wiṘ,Q` and `λa;b@;<λ;c/`. The first half is just basic Vyxal to print "cba" (though I cannot use `cba` because it messes with Hexagony's layout). The second part worked out really nicely, because in order to print in Hexagony, a semicolon is required, but in Vyxal, an unmatched semicolon gives an error. So to fix this, I use lambdas in order to match them, and it just so happened to fit into an exact 3x3 hexagon. Luckily, in Hexagony almost any character that isn't special is taken as its codepoint, so the lambda character is quickly overwritten by anything else that comes after it.
[![](https://i.stack.imgur.com/elqLs.png)](https://i.stack.imgur.com/elqLs.png)
The lambdas are placed so each one proceeds a semicolon, even if they aren't used in the hexagony code (as indicated by the blue trail).
[Answer]
# [Python 3](https://docs.python.org/3/), 26 bytes
```
print('abc'[::-(1/2>0)|1])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EQz0xKVk92spKV8NQ38jOQLPGMFbz/38A "Python 3 – Try It Online")
# [Python 2](https://docs.python.org/2/), 26 bytes
```
print('abc'[::-(1/2>0)|1])
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EQz0xKVk92spKV8NQ38jOQLPGMFbz/38A "Python 2 – Try It Online")
[25-byte version with `exit` instead](https://tio.run/##K6gsycjPM/r/P7Uis0RDPTEpWT3aykpXw1DfyM5As8YwVvP/fwA), which outputs to STDERR instead.
This is basically the same as `print('abc'[::[1,-1][1/2>0]])`, just that it's golfed.
[Answer]
# [Python 2](https://docs.python.org/2) and [Foo](https://esolangs.org/wiki/Foo), 16 bytes
```
print"abc"[::-1]
```
## Python 2
```
print"abc"[::-1]
```
[Try Python 2 online!](https://tio.run/##K6gsycjPM/r/v6AoM69EKTEpWSnaykrXMPb/fwA "Python 2 – Try It Online")
### Explanation
```
print"abc"[::-1]
print             # print... (duh)
     "abc"        # the string "abc"...
          [::-1]  # backwards
```
## Foo
```
"abc"
```
[Try Foo online!](https://tio.run/##S8vP//@/oCgzr0QpMSlZKdrKStcw9v9/AA "Foo – Try It Online")
### Explanation
```
"abc"
"abc"               print the string "abc"
```
[Answer]
# C (gcc) C++ (g++), 59 bytes
```
#include<stdio.h>
main(){puts("abc\0cba"+(sizeof(' ')&4));}
```
[Answer]
# [Fission](https://github.com/C0deH4cker/Fission) / [><>](https://esolangs.org/wiki/Fish) , 11 bytes
```
!R"abc"ooo;
```
[Try Fission Online](https://tio.run/##S8ssLs7Mz/v/XzFIKTEpWSk/P9/6/38A)
In Fission, a particle starts at `R` and prints `abc`.
[Try ><> Online](https://tio.run/##S8sszvj/XzFIKTEpWSk/P9/6/38A)
In ><>, the IP starts at the top-left. `!` skips the next instruction, and `"abc"` pushes [a,b,c] on the stack. `ooo` then pops and prints three times, giving `cba`.
Both programs end at `;`
[Answer]
# [Ly](http://esolangs.org/wiki/Ly) / [><>](https://esolangs.org/wiki/Fish), ~~20~~ 19 bytes
```
"abc"&&ov
;     oo<
```
[Try it with ><>!](https://tio.run/##S8sszvj/XykxKVlJTS2/jMtaAQTy823@/wcA)
[Try it with Ly!](https://tio.run/##y6n8/18pMSlZSU0tv4zLWgEE8vNt/v8HAA)
These languages are very similar, as Ly is based off ><>. However, Ly does not have 2D execution and interprets `&` differently, which I took advantage of here.
Both languages will start by pushing `abc` to the stack. 
For ><>, the `&` instruction moves values to and fro the register. Two in a row will push a value to the register and then take it straight back, essentially a NOP.
For Ly, `&` is a modifier that makes an instruction perform its function on the entire stack. 
`o` means the same thing for both languages, but since it is modified by `&` in Ly, it will print the whole stack, outputting `abc`. In ><>, it will only output `c` (as it is printed from the top down)
`v` is a NOP in Ly, which skips it and goes straight to `;`, ending execution. ><> will instead treat it as a pointer, sending the IP downwards.
It then hits another arrow, sending the IP left. Here, it meets two `o` signs, outputting `b` and `a`.
EDIT: Saved a byte (and fixed ><> crashing)
[Answer]
# CJam and ><>, 12 bytes
```
"ooo;abc
"4>
```
## What CJam sees:
```
"ooo;abc
"
```
String literal, which pushes the string `ooo;abc` (with a trailing newline) to the stack.
```
 4>
```
Slice off the first four characters of the string, leaving `abc`, which is output.
## What ><> sees:
```
"
```
Begins a string literal.
```
 ooo;abc
```
Forms the contents of the string literal. The character codes of the characters in the string are pushed to the stack in reverse order (so `c` is on the top).
```
"
```
The IP wraps around, hitting the `"` a second time, which ends the string literal.
```
 ooo
```
Outputs the top three characters on the stack: `cba`
```
    ;
```
Terminates the program. Neither the `abc` nor any part of the second line is executed.
## Solution with Error: 8 bytes
```
"abc"oo<
```
What CJam sees ([Try it online!](https://tio.run/##S85KzP3/XykxKVkpP9/m/38A "CJam – Try It Online")):
```
"abc"
```
Push a string literal to the stack.
```
    o
```
Output that string literal.
```
     o
```
Try to output again. The stack is empty, so the program crashes.
## What ><> sees:
```
"abc"
```
Push three characters onto the stack in reverse order.
```
    o
```
Print one character: `c`
```
     o
```
Print another character: `b`
```
      <
```
Start moving backwards.
```
     o
```
Print the last character: `a`
```
    o
```
Try to print another character. Since the stack is empty, the program errors.
[Answer]
# [J](http://jsoftware.com/)/[K (Kona)](https://github.com/kevinlawler/kona), 30 bytes
```
NB. :`0:"ABC"
{}[] /.echo'CBA'
```
[TIO - J](https://tio.run/##y/r/389JT8EqwcBKydHJWYmrujY6VkFfLzU5I1/d2clR/f9/AA "J – Try It Online") & [TIO - K kona](https://tio.run/##y9bNzs9L/P/fz0lPwSrBwErJ0clZiau6NjpWQV8vNTkjX93ZyVH9/38A "K (Kona) – Try It Online")
[Answer]
## Javascript / Ruby, 27 bytes
```
0?print('abc'):alert('cba')
```
A shorter version without prints for interpreters (**14 bytes**) :
```
0?'abc':'cba'
```
  
\*\*Explanation\*\*
*NEW VERSION*
`0` is falsy for Javascript but truthy for Ruby, thanks to [pxeger](https://codegolf.stackexchange.com/users/97857/pxeger)
*OLD VERSION*:
`''` is falsy for Javascript, but truthy for Ruby.
*OLD VERSION*:
For Javascript, `[]+[] = ""` as a string concatenation, since the `+` operand is only defined for numbers and strings, and the empty string is evaluated as `false`
Meanwhile, in Ruby, you can concatenate array using the `+` operand, and it is evaluated as `true`
(first participation in PCG ! :))
[Answer]
# [Julia](http://julialang.org/) and [Python 3](https://docs.python.org/3/), 23 bytes
```
print(["abc","cba"][1])
```
[Try Julia online!](https://tio.run/##yyrNyUw0rPj/v6AoM69EI1opMSlZSUcpOSlRKTbaMFbz/38A "Julia 1.0 – Try It Online")
[Try Python online!](https://tio.run/##K6gsycjPM/7/v6AoM69EI1opMSlZSUcpOSlRKTbaMFbz/38A "Python 3 – Try It Online")
Julia uses 1-based indexing while Python uses 0-based indexing
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E) and [2sable](https://github.com/Adriandmen/2sable), 6 bytes
```
…CBAžR
```
Prints `ABC` (OP said it was allowed) in 05AB1E and `CBA` in 2sable, using the fact that 2sable was similar to 05AB1E but the `žR` was added to 05AB1E after 2sable was abandoned.
[Try it online! (05AB1E)](https://tio.run/##MzBNTDJM/f//UcOy5KTEo/uC/v8HAA "05AB1E – Try It Online")
[Try it online! (2sable)](https://tio.run/##MypOTMpJ/f//UcOy5KTEo/uC/v8HAA "2sable – Try It Online")
]