Pip, 12 bytes
A comment-based solution:
aQRVa aVRQa
Takes input as command-line argument; outputs 1
for palindrome, 0
for non-palindrome. Try it online!
Uppercase sequences scan as pairs of letters, with the odd letter out being the first one. So the code that gets executed is a Q RV a
, where a
is the command-line argument, Q
is string equality, and RV
is reverse. Everything after a double space is a comment.
The best non-comment solution I've found so far is quite interesting, but unfortunately it's 13 bytes (try it online):
x:aQRVaVRQa:x
aQRVa
works as above: 1 if palindrome, 0 if non-palindrome. Next, the sequence VRQ
is interpreted as V RQ
, which evaluates the previous result as a function with argument list RQ
. This is bizarre, for a few reasons:
RQ
is an undefined variable, so it's nil, not a list.- Evaluating
1
or0
as a function should be equivalent to calling the functions{1}
or{0}
, which return a constant value regardless of the arguments. - However, there's a bug in the current interpreter such that evaluating
0
actually gives nil. (1
gives1
, as expected.)
Thus, x:aQRVaVRQ
computes either 1
or nil and assigns it to x
. Then a:x
assigns that value back to a
; but since this is the last expression in the program, it is also printed implicitly. (Printing nil results in no output.)
After my next interpreter update, you should get 0
for non-palindromes.