Pip, 1212 11 bytes
ANow comment-based solution:free!
aQRVa aVRQax:RVaQaVR:x
Takes input as a 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.Try it online!
The best non-comment solution I've found so farcore of what we want to do is quite interesting, but unfortunately it's 13 bytes (try it online):
x:aQRVaVRQa:x
aQRVaRVaQa
works as above: 1 if palindrome, 0 if non-palindrome. Next, the sequence VRQ
is interpreted as Vreverse(a) RQ
, which evaluates the previous result as a function with argument list RQstring-equals a
. 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,The code x:aQRVaVRQ
computes either 1RVaQa
or nilcalculates this result and assigns it to x
. Then aVR:x
assigns thatthe value backof x
to the variable aVR
; but since. Since this assignment is the last expressionstatement in the program, itits value is also printed implicitly. (Printing nil results in no outputautoprinted.) Voila!
After my next interpreter updateFor a previous interesting version using some undefined behavior, you should get 0
for non-palindromessee the revision history.