You have to write a program, if its source code is reversed, then it will error.
For example, if your source is ABC
, then reversing it and writing CBA
should crash/throw an error. And ABC
itself should be a vaild program (I mean your primary source should be a valid program). Output of the main source code can be empty, but your ABC
code I mean primary source should not output anything to standard error.
Also the minimum length of a solution is 2 bytes.
Standard loopholes apply, shortest code wins.
-
\$\begingroup\$ @Wasif Would be too similar to challenges in this vein: codegolf.stackexchange.com/questions/192979/… \$\endgroup\$Razetime– Razetime2021年02月27日 07:06:28 +00:00Commented Feb 27, 2021 at 7:06
-
5\$\begingroup\$ Basically any programming language (with the exception of Stack Cats) will error when its code is reversed. \$\endgroup\$Razetime– Razetime2021年02月27日 07:10:03 +00:00Commented Feb 27, 2021 at 7:10
-
\$\begingroup\$ @Razetime another idea is too make the main source error and reversed one valid? (That might be more interesting) \$\endgroup\$wasif– wasif2021年02月27日 07:10:52 +00:00Commented Feb 27, 2021 at 7:10
-
\$\begingroup\$ The question and its idea have already been posted. Changing that would make it a different question, and require all the answers to be deleted (also, that is effectively the same challenge) \$\endgroup\$Razetime– Razetime2021年02月27日 07:13:06 +00:00Commented Feb 27, 2021 at 7:13
-
\$\begingroup\$ @Razetime another possibility to make this a little interesting is to restrict byte limit for this challenge (To 3-4 bytes or somehow like this), it would not require us to delete our answers, because everything is within 2-3 bytes, so possible solutions will be reduced \$\endgroup\$wasif– wasif2021年02月27日 07:24:12 +00:00Commented Feb 27, 2021 at 7:24
18 Answers 18
Malbolge, 2 bytes
Errors via raising a SIGILL (illegal instruction).
DP
Explanation
Forward:
C | [C] | (C+[C])%94 | Action |
---|---|---|---|
0 | D (ord 68) |
68 | No operation. |
1 | P (ord 80) |
81 | Stop execution of current program. |
Reversed:
C | [C] | (C+[C])%94 | Action |
---|---|---|---|
0 | P (ord 80) |
80 | Illegal instruction (stops program) |
1 | D (ord 68) |
69 | Illegal instruction (not executed) |
R, 2 bytes
NA
Outputs NA
, which corresponds to "Not Available", to represent missing values.
On the other hand, AN
errors, as it is literally not available.
A bunch of other examples:
1i
1L
ar
as
by
de
df
dt
gc
gl
Im
is
lh
lm
ls
pf
pi
pt
qf
qr
qt
Re
rf
rt
sd
ts
vi
{}
.C
Jelly, 2 bytes
D€
Try it online! or !enilno ti yrT
How it works
D€ - Main link. Takes no arguments
- Implicitly set the argument to 0 as the chain doesn't begin with a nilad
€ - Generate the range from 1 to 0 ([]) and over each element:
D - Get its digits
Output the empty list, which outputs nothing due to Jelly's output rules
skrow ti woH
€D - Main link. Takes no arguments
€ - € is a quick, which needs a preceding atom upon which to act
Without a preceding atom, parsing fails and the program errors
D - D is ignored as the program has errored
Alternative programs
There are far too many 2-byte programs that also work to fully list them. Instead, here's how to make your own:
- Open Jelly on Try it online!
- Open the Quicks page
- Open the Atoms page
- Choose any single character atom. Enter it into the TIO Code field (Copy-Paste works best)
- Choose any single character quick. Enter it after the atom
- Press Run.
- If this errors, clear the characters and go to step 4
- Voila, you have your answer
Python 2 or 3, 3 bytes
0/1
0/1
is a valid mathematical expression and will result 0 (will show nothing on TIO interpreter) 1/0
(reversed) causes a divide by zero error.
Polygots in a "loooottttttttttt" of languages
-
\$\begingroup\$ Polyglot in about 9 million languages \$\endgroup\$pxeger– pxeger2021年02月27日 07:00:19 +00:00Commented Feb 27, 2021 at 7:00
-
\$\begingroup\$ @pxeger I think so, answers are too broad! \$\endgroup\$wasif– wasif2021年02月27日 07:01:27 +00:00Commented Feb 27, 2021 at 7:01
-
\$\begingroup\$ You can do better: [] is a valid line of code too. \$\endgroup\$Rushabh Mehta– Rushabh Mehta2021年02月27日 19:22:34 +00:00Commented Feb 27, 2021 at 19:22
-
\$\begingroup\$ Two bytes:
()
,{}
,[]
,10
,+0
,~0
,-0
,#!
,0;
, and many, many more. \$\endgroup\$Makonede– Makonede2021年03月05日 22:13:02 +00:00Commented Mar 5, 2021 at 22:13 -
\$\begingroup\$ Another option:
0\
(without the space) \$\endgroup\$Makonede– Makonede2021年03月06日 19:57:46 +00:00Commented Mar 6, 2021 at 19:57
JavaScript, 2 bytes
[]
Errors with ][
-
\$\begingroup\$ @Wasif I know, this challenge is a little broad \$\endgroup\$user100690– user1006902021年02月27日 07:50:10 +00:00Commented Feb 27, 2021 at 7:50
Bash, 2 bytes
wc
Don't think this one has a lot of "polygot"s
other 2-byters sh
,ps
,du
,ls
(if sl
is not installed)
Windows Batch, 2 bytes
:a
This program is an empty label, if reversed then it would search for a drive named a:
, but floppy drives are no longer available!!!
-
\$\begingroup\$ My Windows VM has a virtual floppy drive, does that count? \$\endgroup\$Neil– Neil2021年02月27日 11:34:29 +00:00Commented Feb 27, 2021 at 11:34
Vyxal, 2 bytes
i1
Try it Online! or Try it Reversed!
Explained
Before we begin, i
takes two arguments (we'll call them a
and b
) and returns a[b]
(indexing). 1
simply pushes 1
to the stack.
The program i1
is:
rhs, lhs = pop(stack, 2)
stack.append(lhs[rhs])
stack.append(1)
Because the stack is empty, implicit input is taken for lhs
and rhs
. And because there is no input, 0
is returned each time input is needed. Thus, i
gives "0"[0]
and then pushes 1
.
The program 1i
is:
stack.append(1)
rhs, lhs = pop(stack, 2)
stack.append(lhs[rhs])
Which attempts to push "0"[1]
, which is obviously out of the list. Vyxal doesn't have modular indexing (yet), so this errors.
-
\$\begingroup\$ You always seem to answer in Vyxal because your username is very similar \$\endgroup\$user100690– user1006902021年02月27日 07:49:25 +00:00Commented Feb 27, 2021 at 7:49
-
1\$\begingroup\$ Heh, funny about that. ;p \$\endgroup\$2021年02月27日 08:16:43 +00:00Commented Feb 27, 2021 at 8:16
-
1\$\begingroup\$ Whereas in R,
1i
is valid, buti1
isn't. ;-) \$\endgroup\$Robin Ryder– Robin Ryder2021年02月27日 08:17:19 +00:00Commented Feb 27, 2021 at 8:17
naz, 2 bytes
1o
Any valid 2-byter will throw the error missing number literal
if reversed; I just picked this one because it actually outputs something (0
).
x86-16 machine code, 2 bytes
Full program. Error type is an unhandled SIGSEGV.
Hexdump:
00000000: 63c3 c.
Listing:
63 DB 63 ; Raises an unhandled SIGSEGV
C3 RET ; Not executed
Listing (reversed):
C3 RET ; Return to caller
63 DB 63 ; Not executed
MATLAB/Octave, 2 bytes
pi
When run forward, this yields an approximation of pi
represented as a floating point number. When reversed, it tries to execute the function named ip
which is not defined:
octave:1> ip
error: 'ip' undefined near line 1, column 1
Java, 42 bytes
interface M{static void main(String[]a){}}
This is the shortest valid full Java program. It does not output anything. Since all methods in an interface are implicitly public, we can save bytes by putting the main method inside an interface instead of a class.
The reversed code is clearly invalid syntax:
}}{)a][gnirtS(niam diov citats{M ecafretni
Lua (2 bytes)
Write the following in the command line
=1
Although the =<something>
is supported for backward compatibility, is a deprecated feature in Lua. 1=
triggers the following error:
stdin:1: unexpected symbol near '1'
in Lua 5.4.2.
[BASIC], 2 bytes
?a
a?
The reverse will just generate a Syntax Error
Basically (pun totally intended) if you can't make a 2-3 byte program in almost any language that'll crash if reversed, something is wrong!
Brain-flak, 2
()
Errors on )(
PHP, 2
$=?>
does nothing
<?=$
errors.
MATL, 2 bytes
lt
Try it at MATL Online
Explanation
This program pushes the literal 1
to the stack and duplicates it using t
. When reversed, t
tries to grab it's input argument implicitly and since no inputs are provided it errors out
MATL run-time error: The following Octave error refers to statement number 1: t
---
Unable to fetch user input