Skip to main content
Golfed 1 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

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 or 0 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 gives 1, 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.

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 or 0 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 gives 1, 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.

Pip, 12 11 bytes

Now comment-free!

x:RVaQaVR:x

Takes input as a command-line argument; outputs 1 for palindrome, 0 for non-palindrome. Try it online!

The core of what we want to do is RVaQa: reverse(a) string-equals a. The code x:RVaQa calculates this result and assigns it to x. Then VR:x assigns the value of x to the variable VR. Since this assignment is the last statement in the program, its value is also autoprinted. Voila!

For a previous interesting version using some undefined behavior, see the revision history.

Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

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 or 0 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 gives 1, 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.