[Question]
  [
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
 
 
---
 Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 7 years ago.
[Improve this question](/posts/1798/edit) 
Write a program to test if a string is palindromic, with the added condition that the program be palindromic itself.
  
[Answer]
## Ruby
```
z=gets;puts *z.reverse==z&&1||0||1&&z==esrever.z* stup;steg=z
```
Prints 1 if the input is a palindrome, 0 if it isn't. Input without linebreak.
Doesn't use any comments, instead it uses 2 tricks:
* Short-circuiting: `0` is true-ish in Ruby (only `nil` and `false` evaluate to false), so `1&&z==esrever.z* stup` isn't evaluated and thus can't raise a runtime exception
* The splat/multiplication operator (`*`): To avoid a syntax error in `z=esrever.z stup`, we force the parser to parse this as `z=esrever.z()*stup` by adding a `*`. On the other side, the `*` is parsed as a splat operator, which in a function call splits an array in a series of parameters. If there's only one element instead of an array, it basically does nothing, so `puts *foo` is equivalent to `puts foo`.
Obvious solution using comments (prints true/false):
```
puts gets.reverse==$_#_$==esrever.steg stup
```
[Answer]
**Python without comment**
```
"a\";w=]1-::[w trinp;)(tupni_war=w;";w=raw_input();print w[::-1]==w;"\a"
```
I'm surprised that no one found that trick yet, it should work in most languages!
[Answer]
## Perl
`perl -nle "$s=$_ eq+reverse;print$s;s$tnirp;esrever+qe _$=s$"`
no comment tricks, just cleverly abusing the substitution operator (hey, perl variables start with a $ too, so what?)
[Answer]
# Python 2.7
```
s=raw_input();print'YNEOS'[s!=s[::-1]::2]#]2::]1-::[s=!s['SOENY'tnirp;)(tupni_war=s
```
[Answer]
## C
```
#include <stdio.h>                   //
#include <string.h>                  //
int main() {                         //
  char str[1024];                    //
  fgets(str, sizeof(str), stdin);    //
  int i = 0, j = strlen(str) - 2;    //
  for (; i < j; i++, j--)            //
    if (str[i] != str[j]) {          //
      printf("no\n");                //
      return 0;                      //
    }                                //
  printf("yes\n");                   //
}                                    //
//                                    }
//                   ;)"n\sey"(ftnirp  
//                                }    
//                      ;0 nruter      
//                ;)"n\on"(ftnirp      
//          { )]j[rts =! ]i[rts( fi    
//            )--j ,++i ;j < i ;( rof  
//    ;2 - )rts(nelrts = j ,0 = i tni  
//    ;)nidts ,)rts(foezis ,rts(stegf  
//                    ;]4201[rts rahc  
//                         { )(niam tni
//                  >h.gnirts< edulcni#
//                   >h.oidts< edulcni#
```
Running example:
```
$ gcc -std=c99 c.c && ./a.out 
blahalb
yes
```
[Answer]
# Golfscript
```
.-1%=#=%1-.
```
* just with comment trick
* input without \n at the end
* perform matching char by char (even for punctuation)
* returns 1 for success, 0 for failure
[Answer]
# PHP
```
echo strrev($z)==$z;#;z$==)z$(verrts ohce
```
Facts:
* `$z` string, the input string to check
* `$t` boolean, TRUE if the input string `$z` is palindrome, FALSE otherwise
* Using comments to help me make the code palindrome.
* Outputs `$t`
* Source itself is a palindrome
The reason why it will not be possible to implement palindromic palindrome checker in PHP it's because PHP variables are named starting with a `$`. You cannot end an identifier name with `$` in PHP.
[Answer]
# PHP
```
<?php eval/*/*/(';{$i=fgets(STDIN,2e9);};{$a="strrev";}{var_dump("{$i}"=="{$a($i)}");}/*}{*\{;("{(tupni$)a$}"=="{putni$}")ohce}{;"verrts"==a$};{;(9e2,NIDTS)stegf=i$);');/*\*\eval php?>
```
Uses some odd tricks to avoid the `$` issue, technically isnt a palindrome as I had to sneak a `;` in at the end.
```
 <?php $i = fgets(STDIN,2e9); echo $i == strrev($i);/*\;(i$)verrts == i$ ohce ;(9e2, NIDTS)stegf = $i php?>
```
This is a working one that uses PHP's `/* */` comments and the fact that you don't need the end for them.
[Answer]
# [Fuzzy Octo Guacamole](https://github.com/RikerW/Fuzzy-Octo-Guacamole), 17 bytes
```
^Cz.=i_;@;_i=.zC^
```
Not exactly sure how the win is defined, but I put the byte count up top.
`^` gets the input and pushes it to the first stack.
`C` copies the first stack to the second.
`z` reverse the top of the stack, so "as" becomes "sa".
`.` shifts the active stack, so the active stack has the input, and the inactive one has the reversed input.
`=` checks for equality, returning `0` for equality.
`i` inverts the ToS, so `0` becomes `1`, and anything else pretty much becomes `False`.
`_` pops and sets the temp variable which the `;` then prints.
`@` ends the program manually, so it doesn't hit the reversed part. This makes the palindrome.
[Answer]
## CoffeeScript
I actually struggled with the reverse spellings of 'split', 'reverse' and 'join' :\
```
p=(s)->s.split('').reverse().join('')==s#s==)''(nioj.)(esrever.)''(tilps.s>-)s(=p
```
[Answer]
## Groovy
```
print args[0]==args[0].reverse()?1:0//0:1?)(esrever.]0[sgra==]0[sgra tnirp
```
[Answer]
# Python 3, 55 bytes
Uses a comment, but is shorter than the other Python one that uses comments.
```
s=input();print(s==s[::-1])#)]1-::[s==s(tnirp;)(tupni=s
```
[Answer]
# Javascript
```
function a(b){return b==b.split('').reverse().join('')}//})''(nioj.)(esrever.)''(tilps.b==b nruter{)b(a noitcnuf
```
Hard to do it without comments...
]