So the puzzle is to write a hello world program in your language of choice, where the program's source file as a string has to be a palindrome.

To be clear, the output has to be exactly "Hello, World".


Well, with comments it seems trivial (not that I thought of it myself of course [sigh].. hat tip to cobbal).

So new rule: no comments.


I feel kind of bad editing someone else's question to say this, but it will eliminate a lot of non-palindromes that keep popping up, and I'm tired of seeing the same simple mistake over and over.

The following is NOT a palindrome:


The following IS a palindrome:


Brackets, parenthesis, and anything else that must match are a major barrier to palindrome-ing, yes, but that doesn't mean you can ignore them and post non-palindrome answers.

Languages represented thus far:

C, C++, Bash, elisp, C#, Perl, sh, Windows shell, Java, Common Lisp, Awk, Ruby, Brainfuck, Funge, Python, Machine Language, HQ9+, Assembly, TCL, J, php, Haskell, io, TeX, APL, Javascript, mIRC Script, Basic, Orc, Fortran, Unlambda, Pseudo-code, Befunge, CFML, Lua, INTERCAL, VBScript, HTML, sed, PostScript, GolfScript, REBOL, SQL


If I write a normal hello world in c++ without comments or newlines and append a '/', then I have the first half of a working palindromatic program...

Ah, the #include causes a small problem

Like this:

#include <iostream>//
int main(void){std::cout<<"Hello, world!"<<std::endl;}/
I haven't tried C++, but I know that you can use printf in C without the #include, at least on some compilers.
on all compilers -- just declare it. int printf(const char* s, ...);
Lou Franco
+94  A: 

cheating by comments in a shell script of your choice (bash for me)

echo 'hello world' # 'dlrow olleh' ohce


And using the preprocessor in c you can use

#define foo fidne#
#include <stdio.h>

int main() {
    printf("hello world\n");

#if 0
0 fi#
;)"n\dlrow olleh"(ftnirp    
{ )(niam tni

>h.oidts< edilcni#
#endif oof enifed#

Edit: updated C code to remove all warnings in gcc (still one in Comeau though)
updated C code to be palindrome (thanks Can Berk Güder)


And the simple, elegant, elisp solution

(message "%s" "hello world")'("dlrow olleh" "s%" egassem)

Although this is not a strict palindrome as I had to reverse parens

damn, I should have thought of that.
Assaf Lavie
+1 - beat me to it :)
Eric Petroelje
I don't think comments should count ;D
I agree. No comments. Though hat's off to cobbal for the quick thinking.
Assaf Lavie
cobbal, your C program does not compile. I tried with Comeau.
Assaf Lavie
gcc compiled it for me, it did give a warning though
"ComeauTest.c", line 15: error: extra text after expected end of preprocessing directive #endif enifed#
Assaf Lavie
Assaf Lavie
take off strict mode and it just spits out warnings
@cobbal, yea. but no fair. It's not a valid program according to the Standard AFAIK.
Assaf Lavie
)(main int should be )(niam tni
Can Berk Güder
The C one still has an error in comeau:"ComeauTest.c", line 15: error: extra text after expected end of preprocessing directive #endif oof enifed# ^
Assaf Lavie
+1 very ingenious with the C ;-)
David Zaslavsky
The second "%s" in the elisp example should be "s%"
fixed now, thanks
The preprocessor trick is great!
Valid is subjective - maybe 'valid' to cobbal is 'compiles, runs, and produces expected output'
Erik Forbes
unfortunately the spec does specify that #endif must be followed by a new line :(
Relaxing the comment requirement a little, insert // between foo and fidne (and between endif and oof) to make it valid C++.
"the spec does specify that #endif must be followed by a new line" Yes, but a LOT of code out there in the real world has extra text after the #endif, and nearly every C compiler (other than Comeau, apparently) will allow it.
Mark Bessey
You sir are the definition of cheeky.
Lela Dax
+22  A: 

Surprise surprise, Jon Skeet has done that ;-)

David Zaslavsky
Am I the only one who thought Skeet's answer there was incredibly lame? Sorry, I must've missed the fanboy bus ;)
Maybe... it's kind of funny. At least the first time you see it. (It's not just because it's Jon Skeet!)
David Zaslavsky
I thought it was lame from the first time on. :)
I do agree with ojrac (and I did see the answer in the first time). Nevertheless, Mr. Skeet answers usually are great.
Alex. S.
Jon Skeet's solution does not, in fact, solve the problem given. It prints "Hello World", not "Hello, World".
@ojrac: no you aren't

Well, easy if you allow comments.

Just (pseudo-code for any language):

program-that-prints-hello-world // dlrow-olleh-strnirp-taht-margorp

Of course, if you disallow comments, then it becomes much harder.

Here's a C# version:

class P { static void Main() { System.Console.WriteLine("Hello world"); } } //
} };)"dlrow olleH"(eniLetirW.elosnoC.metsyS { )(niaM diov citats { P ssalc

Just put everything on the second line after // with a space in front.

Lasse V. Karlsen
yup, the comments do make it easier. so let's try it without them :)
Assaf Lavie
Well, I'd think that any language that uses braces will have a hard time then, as in the second half all the braces will be in the wrong order, just to take one problem at a time.
Lasse V. Karlsen
I agree. I'm trying it out in C++ and I fear I might have to resort to tons of macro magic to make it work.
Assaf Lavie
In C or C++, you're stuck with trying to end the program with ")niam tni". If I do something like "#define tni ;", I need to have a "; int enifed#" line somewhere, and '#' is not allowed in identifiers.
David Thornley
+15  A: 


Not sure if this is considered cheating or not :P

int main() //
{ // }
  // ;0 nruter
  printf("Hello, World"); // ;)"dlroW, olleH"(ftnirp
  return 0; //
} // {
// )(niam tni
Parens should be reversed in the comments.
The soliduses (slashes) need to be reversed too.
+69  A: 


print + "Hello, World\n";"n\dlroW ,olleH" + tnirp
+1 ... what does Perl interpret the +tnirp to be?
David Zaslavsky
Nice. I had a hunch a Perl answer will not be late in coming.
Assaf Lavie
Strictly speaking, the second ; is unnecessary - it's still a palindrome and it still runs properly. And, honestly, a Perl answer should be a one-liner, shouldn't it?
Chris Lutz
@David: since "tnirp" is not a function, it evaluates to the string "tnirp". Since "+" is a numerical operator, both strings are evaluated in numerical context (to zero). The 2 zeroes are added together, and the result is not used for anything (i.e. thrown away).
@Chris Lutz: you're absolutely right :)
using 'say', you could shorten this guy by 8 characters. :)
Robert P
Could you? I'm not running Perl at this computer, but it looks like the + is essential to make this a valid program, as opposed to something that spits out the output and then fails.
David Thornley
@Robert P - You could, but then you'd have to add "use feature 'say';" at the beginning. And ";'yas' erutaef esu" at the end. You lose more than you gain.
Chris Lutz
@runrig: Works for me (perl 5.8.8). It appears that unary + is a nop on strings.
(println "Hello, World!") ; )"!dlroW ,olleH" nltnirp(

I cheat.

What language is that?
Michael Myers
any language, it prints before it throws an exception, ha
Shawn Simon
Not a palindrome. The parens end up backwards, beginning with a closed paren and ending with an open paren.
Brian Carper
The language is Clojure, and he is right, I thought no one would notice :(
@Shawn No, this doesn't throw an exception. ; denotes a single line comment in Clojure.
+2  A: 

Help. I got this far in C++ (using macros). So I'm posting this as a wiki and welcoming help.

#define x // fidne# 

#include <iostream>
int main() { std::cout << "Hello, World\n"; }
#ifdef N
N fedfi#
} ;"n\dlroW ,olleH" << touc::dts { )(niam tni
>maertsoi< edulcni#

#endif // x
Assaf Lavie
+39  A: 

That should work on most shells (sh, bash and (thanks to Paulius Maruška) even in Windows ;-) ):

echo Hello World || dlroW olleH ohce

proof (the key is the lazy evaluation if echo Hello World succeeds, which does):

$ echo Hello World || dlroW olleH ohce
Hello World

Another one in sh/bash:

   alias dlroW=true saila=true
echo Hello World;dlroW olleH ohce
   eurt=alias eurt=World saila

EDIT: My old one (in bash, too) was not correct:

cat <(echo Hello World >&2;2&> dlroW olleH ohce)< tac

is no palindrome since the brackets are the wrong way and it needs a file called tac in the actual directory.

Johannes Weiß
very nice, tac must be a file though
very nice indeed
Assaf Lavie
+1 for not using comments
love the alias one, very creative
But can you make it a haiku? ;)
Michael Myers
You should update your answer, because the unix shell things works very nicely on Windows command prompt too. :)
Paulius Maruška
mmyers: hmm, a haika get's difficult since I can't even pronounce dlrow so it gets difficult to count syllables. Paulius Maruška: Thanks! I did :-)
Johannes Weiß
+4  A: 

Write in "in your language of choice" leaves a pretty big hole. My language of choice for this problem is a home-brew language consisting of one command. So here is the code calling that one command:


Of course what that command does is print Hello World.

Mark T
See David's answer referring to Jon Skeet's one-character program.
Michael Myers
1 point for originality. However you must submit your compiler, too :)
And the compiler must also be a palindrome!
Chris Lutz
ha ha, pretty hard if you also provide the palindrome code of your palindrome compiler to compile itself to a palindrome binary...
Alex. S.
@Alex - I thought the palindrome binary was a bit high of a requirement, since you'd basically have to write it in assembly to get that effect, but hey.
Chris Lutz
please post your compiler gzipped - the zipped file of course being a palindrome!
petr k.
+6  A: 

Here's what I have so far in Java:

;class tni
/*//;"*/{ public static void main(String[]gnirtS) { /*"
+"*/System.out.println(new StringBuilder().toString()+'H'+'e'+'l'+'l'+'o'+','+' '+'W'+'o'+'r'+'l'+'d'); /*"
+"*/} /*"
+"*/String gnirtS = " = String gnirtS/*"+
"*/ }/*"+
"*/ ;)'d'+'l'+'r'+'o'+'W'+' '+','+'o'+'l'+'l'+'e'+'H'+)(gnirtSot.)(redliuBgnirtS wen(nltnirp.tuo.metsyS/*"+
"*/ { )String][gnirtS(niam diov citats cilbup {/*";//*/
int ssalc;

Only one of the comments is in violation of the spirit of the rules: the //} at the very start. The rest are just to mask newlines; I could take them out if I wrote the main part of the program on one line.

The center of the palindrome is the quotation mark: String gnirtS = "

I'm pretty sure it's actually a palindrome. What's the easiest way to check?

EDIT: It wasn't quite, but now it is.

Michael Myers
equal(reverse(s), s)...
Assaf Lavie
+26  A: 

In common lisp (using no comments or syntactic sugar). Prints only "Hello World!" and returns NIL.

(let (tel etouq)
  (let (tamrof etouq)
    (format t "Hello World!"
            "!dlroW olleH" t tamrof)
    (quote format)
  (quote let)
Sebastian Krog
Not a palindrome (your parentheses aren't reversed).
Michael Myers
Your right! It is awfully hard to fix, though. Another language will have to do!
Sebastian Krog
actually, I think that makes it more palindromic somehow, it's almost a mirror image
I don't remember how format works, but couldn't you reduce that to: (format t "Hello World!" "!dlroW olleH" t tamrof)
No, because "tamrof" at the end of your function call is a symbol with no reference.
Sebastian Krog
Using a quote character (like cobbal did in his elisp above) easily reduces the size, but it feels sort of like a comment trick to me, so i spent quite some time getting around it.
Sebastian Krog
There's a new challenge: making a Hello, World program that's a mirror image of itself!
+2  A: 
Steven Huwig
not a palindrome, probably. Block delimiters kill this.
Steven Huwig
+8  A: 

In Ruby,

tcepsni = puts "hello world!" || "!dlrow olleh"
stup = inspect

(argg, there's a newline)

Gaetan Dubar
Just change to print then. `print %"Hello, World!" || "!dlroW ,olleH"% tnirp`
Jonas Elfström
+191  A: 

In a language that shall not be named:

David Zaslavsky
How did you ever manage to come up with that? Is it original?
Michael Myers
Just trial and error... it wasn't that hard, it just took a little time. It's original as far as I know.
David Zaslavsky
Looks like "BrainF*ck"
Cory Larson
Why do you think I didn't name it ;-) But yes, Brainf*ck it is.
David Zaslavsky
Sir, that is amazing. That is a nice strategy for making brainf*ck palindromes.
Chris Lutz
(Brain)F*ckin brilliant
Wow. Just awesome. This deserves to be #1.
I'm tempted to take this extreme upvoting as a sign that I should attempt a smaller solution in the same language.
Chris Lutz
Who knows what people will go for ;-) I bet there are shorter solutions out there waiting to be discovered - I never tried to find them though.
David Zaslavsky
+1 Very good. I can't decide whether this is better than the binary one, though.
Eduardo León
Massive respect.
+1 for using bf ;)
How is this a palindrome with this string in the middle: "<.<.<.<.<.<.<.<.<.<.<.<.<.<"? Maybe there's a problem with my browser?
That string itself is a palindrome. And everything before it is the reverse of everything after it. So the whole program is a palindrome.
David Zaslavsky
Bravo sir, bravo.
Man. You got way too much time! `;3`
Xavier Ho
+15  A: 

Or in yet another language that shall not be named:

"!dlroW olleH">:#,[email protected]_,#:>"Hello World!"

Sebastian Krog
Any Befunge program deserves respect. :-)You might want to use different tags or something to prevent Stackoverflow's syntax highlighting from making everything look like a comment.
This is technically not a valid palindrome in Befunge. Befunge(93) programs require an 80x25 instruction grid, meaning if you simply placed your code at 0,0 there would be 24 empty rows of NOOPs (whitespace), so it would be a palindrome vertically.
Loren Segal
There's nowhere in the original specification where a full 80x25 grid is required as *input*, it is merely represented as such by the interpreter/compiler.
Sebastian Krog
Besides, this is written in Funge-98, which doesn't have the fixed grid size of Befunge-93. The program does also work in Befunge-93, but that's another matter.
+46  A: 

Python 2.5:

'''dlroW ,olleH' tnirp
print 'Hello, World'''
David Zaslavsky
brilliant! I was trying to make something like this, but I couldn't get it working
Nice, I was thinking that a Python solution wouldn't be possible. You can shorten it to three lines though: keep the middle line the same, and make the first line '''dlroW ,olleH' tnirp
Nice observation... edited in, thanks ;-)
David Zaslavsky
One liner version `"""dlrow ,olleH" tnirp;""";print "Hello, world"""`
Do docstrings count in the "no comments" rule?
+73  A: 

In the Machine Language Monitor on an Apple //e, type N300G003N to run this program:

300: A2 0C BD 0B 03 20 ED FD CA D0 F7 60 E4 EC F2 EF D7 A0 AC EF EC EC E5 C8 8C 5E CE CE FE CA 0A 7D FE 2F CE 4E 06 7F 0D AC DF DE 02 30 B0 DB C0 2A :003
Mark Stock
From AppleSoft BASIC, PRINT "Hello, World" : END : DNE : "dlroW ,olleH" TNIRP
Mark Stock
+1 for answer. I wish I could give another +1 for it being on the Apple ][e.
+14  A: 

In HQ9+,



As the challenge clearly notes, the output has to be exactly "Hello, World" whereas HQ9+ prints "Hello, world!" and so here is a special version of HQ9+ written in C that when compiled will output exactly "Hello, World" using the following command:

./hq9 "" -9qH H one letter palindrome
Mark Stock
aww, beat me to it! glad i thought to check the comments for hq9+ before posting :)
Martin DeMello
+1  A: 

In python 2 lines:

tnirp = 'Hello, World' # print tnirp
print tnirp # 'dlroW ,olleH' = print

can be wrote in 3 lines........

Andrea Ambu
Now, can you do the same without comments? :)
It would be challenging, I'll try, for now I did it in plain bash :D
Andrea Ambu
Erm, if you go with comments: print('Hello, World') # )'dlroW ,olleH'(tnirp
it's the same :)
Andrea Ambu
+152  A: 

I started from Tiny Programs and wrote my own assembly. Sure, maybe it can be reduced further, but I don't know which other ELF header fields I can subvert for use as code while still being portable.

$ wc -c hellolleh
245 hellolleh
$ xxd hellolleh
0000000: 7f45 4c46 0101 0100 0000 0000 0000 0000  .ELF............
0000010: 0200 0300 0100 0000 5000 9331 2c00 0000  ........P..1,...
0000020: 0000 0000 0000 0000 3400 2000 0100 0000  ........4. .....
0000030: 0000 0000 0000 9331 c040 cd80 f800 0000  [email protected]
0000040: 7401 0000 0700 0000 0010 0000 f7d8 ebe6  t...............
0000050: 686f 726c 6468 6f2c 2057 6848 656c 6cb8  horldho, WhHell.
0000060: 0400 0000 bb01 0000 0089 e1ba 0c00 0000  ................
0000070: cd80 bb00 0000 00e9 baff ffff bae9 0000  ................
0000080: 0000 bb80 cd00 0000 0cba e189 0000 0001  ................
0000090: bb00 0000 04b8 6c6c 6548 6857 202c 6f68  ......lleHhW ,oh
00000a0: 646c 726f 68e6 ebd8 f700 0010 0000 0000  dlroh...........
00000b0: 0700 0001 7400 0000 f880 cd40 c031 9300  [email protected]
00000c0: 0000 0000 0000 0000 0100 2000 3400 0000  .......... .4...
00000d0: 0000 0000 0000 0000 2c31 9300 5000 0000  ........,1..P...
00000e0: 0100 0300 0200 0000 0000 0000 0000 0101  ................
00000f0: 0146 4c45 7f                             .FLE.
$ file hellolleh
hellolleh: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, corrupted section header size
$ ./hellolleh
Hello, World

(You can use xxd -r to load this hexdump back into a binary file.)

+1, this may be my favorite
David Zaslavsky
That is a feat of genius.
Chris Lutz
Wow! Very impressive! +1
Eduardo León
Wow ! +1
+23  A: 

Here's my answer in TCL:

proc unknown args {puts "Hello World!"}
}"!dlroW olleH" stup{ sgra nwonknu corp

Gotta love a language where the quote rules are really more guidelines than rules. The very fact that line 2 makes no sense causes line 1 to greet the user.

Actually, i think the proc unknown mechanism in tcl is really helpful in some cases and I miss it in other languages.

So basically that's saying that if the interpreter can't understand something, it should 'puts "Hello World!"' ? Very clever!
Michael Myers
Myfirst version just had a return for the uknown, and it just ignored the palindrone crud. Im completely pleased to put the garbage to work.
Also, I learned that I can name a proc }"dlroW . Show me another language where that's legal And i'll show you two brain-damaged languages!
This isn't a palindrome. The second pair of braces are opposite.
Lucas Oman
@Lucas Oman: Actually, they are not. If you reverse the second line, the 'backwards' braces become forward. Many other answers to this question make that mistake.
Since the question is closed I'll put my Tcl answer here. Not as elegant as the above "unknown" trick through.puts \110ello,\x20World;\151f 0 f151\;dlroW02x\,olle011\ stup
@TokenMacGuy: OK, I'll show you Forth, where `: ? . ! ;` is typically part of the language.
David Thornley
`puts Hello\ World;#;dlrow \olleH stup` though it makes me feel dirty using a comment. Not as much as voting for that abortion of a solution would though. (Damnit, I'm a Tcl developer! I refuse to endorse ugliness in my creations!)
Donal Fellows
+3  A: 

Using comments:

/**/print"Hello, World!";/*/"!dlroW ,olleH"tnirp/**/
unexpected stringUnexpected 'trnip'.At line #2
Kuroki Kaze
I could swear it did work. But I now used comments instead.
+7  A: 

J, no comments.

1!:2&2['Hello, World'['dlroW ,olleH'[2&2:!1
Again, the brackets and parentheses aren't reversed. It's sort of a mirror image this way, except for all those other characters.
Michael Myers
Fixed. Actually, that made it shorter....
Ah, thanks for the typo fix (indeed it was).
+9  A: 

Perl, inspired by the awk and php solutions:

BEGIN{print"Hello, World";exit}tixe;"dlroW ,olleH"tnirp{NIGEB

It exits before it discovers that the remainder of the file doesn't make any sense.

+1 for extreme cleverness.
Chris Lutz
you're missing a { in the middle it seems :D
@stefan: In an odd length palindrome such as this, the middle character doesn't need a matching character. Besides, a { would be a mirror image character to the }.
For the record, I think he could add in a } after the middle } and it would work all the same - Perl should ignore it just as well. Although a "\n" at the end might be nice.
Chris Lutz
+51  A: 

Haskell. Actually pretty easy :)

main = putStr hw
hw = const "Hello, World" ab
a = ba ; niam = main ; ab = a
ba "dlroW ,olleH" tsnoc = wh
wh rtStup = niam

Or, in a comment by Reid Barton:

main = putStr `id` "Hello, World"
niam = main
"dlroW ,olleH" `di` rtStup = niam

Another variation:

main = const putStr main "Hello, World" where erehw "dlroW ,olleH" niam rtStup tsnoc = niam
+1 for declarative languages making this easier.
Steven Huwig
good thing haskell doesn't need so many parenthesis :)
A shorter solution: `main = putStr \`id\` "Hello, World" ; niam = main ; "dlroW ,olleH" \`di\` rtStup = niam`
Reid Barton
@Reid Barton: Wow, I totally didn't think of that trick at all. You're awesome!
Wow, i didn't know you could do that in haskell @[email protected]". Living and learning.
Alessandro Stamatto
+1  A: 

Python is really tough. Here's the best I can do.

"hello world"
tnirp, fi = True, __doc__#
if tnirp:print fi
#__cod__ ,eurT = if ,print
"dlrow olleh"
+2  A: 

Plain bash.

echo "Hello World" || "dlroW olleH" oche
Andrea Ambu
+3  A: 


forward   :=  method
"Hello, world" print
tnirp "dlrow, olleH"
dohtem  =:   drawrof

Since you allowed any language I want, I can cheat\b\b\b\b\bdefine a new language, in which the empty string translates to the program that prints out "hello world". Since the empty string is a palindrome, I present my solution in this language: "".

+1  A: 

here's my language:
a is equivelant to white space
b prints "Hello, world"

so here's the program:

hasen j
Maybe a new rule should be implemented: No made up languages. :-)
Or you have to provide the interpreter/compiler too :)
Every language was made up at some point in history.
+1 for a creative solution
Joe D
+15  A: 

Shortest yet (in TeX):

Hello, world\end dne\dlrow ,olleH
Wow, it's even shorter than the APL solution!
Should the slashes be reversed, since the parens are?
@John no, the parens aren't mirrored - example palindromes `Hello/-/olleH` or `Hello(-(olleH`
+1  A: 

Common Lisp:

(or' "Hello, World" "dlroW ,olleH" 'ro)

Both shortest and simplest one? SBCL + Slime:

"dlroW ,olleH""Hello, World"
Not quite a palidrome, since the last character is not the same as the first character.
Michael Myers
MHO: As a valid Lisp program, it *has* to start and to end with a paren, and in between there are no parens.No rule on earth is absolute. You have to know when (intelligently) to add an exception to a rule.
+9  A: 


puts %"Hello, World!" || "!dlroW ,olleH"% stup
Shorter `p %'Hello, World' % 'dlroW ,olleH'% p`
Jonas Elfström
+4  A: 

In APL :

'Hello World!',13↓31,'!dlroW olleH'

And within a dynamic function (only in Dyalog APL dialect) :

⍬{'Hello World!',13↓31,'!dlroW olleH'}⍬

Of course, again the brackets make it a mirror image rather than a strict palindrome.

Of course, APL would have an easy way to do it. :-)
Even better than my J solution... man I wish I had an APL interpreter :)
Actually, does this write to stdout (1!:2 in J) or just return the string (which gets printed by the REPL)?
+13  A: 

And people say this is hard in python (edited, didn't see the "no comments" rule)...

" \"" and print('Hello, world') and " dna )'dlrow ,olleH'(tnirp dna ""\ "

I challenge anyone to do better: this not only is one line, but it returns None so you don't get any extra output if you type it into the Python REPL.

Dietrich Epp
Py3k? My Python 2.5.4 doesn't like `print` as a function.
+1 for figuring out the backslash thing.
Python 2.x version (one line): `" \"dna enoN;'dlrow olleH'tnirp;enoN dna"and None;print'Hello world';None and"\ "`
One line, Python 2.x, 73 characters: " \""and None;print 'Hello, world'or"ro'dlrow ,olleH' tnirp;enoN dna""\ " OR, if you don't care about the return value, 57 characters: " \"";print 'Hello, world'or"ro'dlrow ,olleH' tnirp;""\ "
Dietrich Epp

JavaScript (cheating):

alert("Hello world"); // ;)"dlrow olleH"(trela
+3  A: 

mIRC Script:

//echo Hello, World | alias dlrow noop poon world saila | dlroW ,olleH ohce//
+13  A: 

Basic (Someone had to do it)


Explanation: Basic is an interpreted language. The interpreter doesn't parse the source it doesn't need to. ':' is statement separator like ';' in C-like languages.

In fact this works too, it prints Hello World, but stops with an error.

Chetan Sastry
Works for me on an Apple 2e emulator!. however, You don't have a palindrone. The last token is 10, but should be 01 for this to be a correct. Works though.
Only applies to those BASICs for which "The interpreter doesn't parse the source it doesn't need to" is strictly true. Counterexamples include QBasic (parses all code before running, and I think compiles it internally) and Spectrum BASIC (doesn't allow syntax errors to be entered into the program). But you've got me wondering if it can be done in Spectrum BASIC....
@TokenMacGuy: To make your example 8 characters shorter<code>1 PRINT "HELLO WORLD":END:DNE:"DLROW OLLEH" TNIRP 1</code>Some BASICs might even let you remove 4 more spaces.

Windows PowerShell:

"Hello World" # "dlroW olleH"
Keith Hill
+6  A: 
"Hello, World" || "dlroW ,olleH"

This is an even shorter variation on several that we've seen already. The interesting thing about this one is that it works in several languages, depending on your interpretation of the rules (whether quotes are allowed to be printed out or not):

Javascript, as executed in the Spidermonkey interpreter:

$ js
js> "Hello, World" || "dlroW ,olleH"
Hello, World


$ irb
irb(main):001:0> "Hello, World" || "dlroW ,olleH"
=> "Hello, world"
Brian Campbell
+2  A: 


(alert)('Hello, World') && ('dlroW ,olleH')(trela)
Mike Samuel
Not a palindrome: the parens need to be reversed. sorry.
Assaf Lavie
Quite right. Here's one that worksi = nulli/=document.body.innerHTML = 'Hello, World',0//0,'dlroW ,olleH' = renniLMTH.ydob.tnemucod=/illun = i
Mike Samuel
Ack. It ate my formatting. There should be newlines after "null", after ",0/", and after "=/i".
Mike Samuel
maybe not, but I like it.
hasen j
+1  A: 


;puts 'Hello! World'.tr'!,;q%,',%q;,!'rt.'dlroW !olleH' stup;

I was really hoping to find a way to make good use of the second half (string) rather than having it sit there just like if I had added a comment... But so far I've only got it fixing the exclamation into a comma...

+3  A: 

Orc: "hello world" << "dlrow olleh"

The "<<" runs both the LHS and RHS in parallel, but only returns the value of the LHS, which the interpreter prints. Follow the Orc link to learn more about Orc (there is a "Try Orc" link where you can run this program yourself).

but the "<<" make it not a palindrome, no?
Assaf Lavie
+5  A: 

Python 2.x:

"t\";]41:1[";print"\tHello, World..dlorW ,olleHt\"tnirp;"[1:14];"\t"

@Dietrich Epp: 5 characters shorter.

i KNEW there was some kind of solution using backslash escapes, but couldn't make my head do it. +1

yet another Haskell solution:

main = putStrLn "Hello World!" -- "!dlroW olleH" nLrtStup = niam

+2  A: 


      PROGRAM PAL!      
      print *,'Hello World!' !      
      ! '!dlroW olleH',* tnirp      
      !LAP MARGORP      

or the slightly shorter:

      print *,"Hello, World"!
      !"dlroW ,olleH",* tnirp

False ( (cheating)

0'}"Hello, world"{{"dlrow, olleH"}'0
+1  A: 


`?d`?c`?d`?c`?d`?c`?d``v````````````.H.e.l.l.o.,. .W.o.r.l.di`d
d`id.l.r.o.W. .,.o.l.l.e.H.````````````v``d?`c?`d?`c?`d?`c?`d?`
+49  A: 


Output "Hello, World".
Ignore the two next lines.
.senil txen owt eht erongI
."dlroW ,olleH" tuptuO
LOL! that is a good cheat hahah!
Made me laugh :)
Kuroki Kaze
Well actually, this would work in Perl, with `__END__` or `=cut` :)
hehe. this is silly.
+10  A: 


0"dlroW ,olleH"v<
@_,^         >#:^
^:#>         ^,[email protected]
<v"Hello, World"0
befunge makes such pretty code. this code, in addition to being a palindrome, is also symmetric about the origin!
+1  A: 

Here it is in CFML, without using comments:

<cfsetting enablecfoutputonly="true"/>
<cfoutput>Hello, World</cfoutput>
>tuptuofc/<dlroW ,olleH>tuptuofc<
>/"eurt"=ylnotuptuofcelbane gnittesfc<

Or, an extended version that would still work inserted into almost any page, even if global debugging is on:

>/trobafc<<cfcontent reset />
<cfsetting enablecfoutputonly="true" showdebugoutput="false" />
<cfoutput>Hello, World</cfoutput>
>tuptuofc/<dlroW ,olleH>tuptuofc<
>/ "esalf"=tptuogubedwohs "eurt"=ylnotuptuofcelbane gnittesfc<
>/ teser tnetnocfc<<cfabort/>
Peter Boughton


print "Hello, World" # "dlroW ,olleH" tnirp
not in the spirit of the 'no comments' rule. Not really in the letter either.
The "no comments" rule wasn't there when I posted this.
+2  A: 
<?php ">?tixe;";echo 1?"\x48ello, World":"dlroW ,olle84x\"?1 ohce;";exit?>" php?<
+2  A: 

Another language that cannot be named, albeit in a different sense:

100 108 114 111 87 32 44 111 108*101 72!!!!!!
!!!!!!27 101*801 111 44 23 78 111 411 801 001
+10  A: 

I wanted to code a C solution that doesn't use #if or #ifdefs because I think of them as just another form of comments.

So! Here is my attempt, completely free of comments, #ifs and #ifdefs.

I used gcc 4.3.2, with the -Wall flag; it compiled without warnings or errors.

#define niam ){printf("Hello, World\n");return 0;}x(( z enifed#
#define x(x)
#include <stdio.h>
#define tni 0)
#define y int y=
int main(niam tni
=y tni y enifed#
)0 int enifed#
>h.oidts< edulcni#
)x(x enifed#
#define z ((x};0 nruter;)"n\dlroW ,olleH"(ftnirp{) main enifed#
+3  A: 


x=print"Hello, world"=="dlrow ,olleH"tnirp=x
+1  A: 

shell + Perl

perl -e 'print "Hello, World\n"' '"n\dlroW ,olleH" tnirp' e- lrep
Neat. Presumably the arguments following the -e program text get passed to the program. I bet this works for other UNIX tools, too...
Mark Bessey


palindrome source code palindrome output text palindrome output file

echo "txt.Hello worlddlrow olleH.txt" >> "txt.Hello worlddlrow olleH.txt" ohce

The two >> are not repeated...
@SeanJA So what?This doesn't print exactly "Hello, World" so it doesn't answer the original question....
c:\>type txt.hello worldlrow olleh.txtThe system cannot find the file specified.Error occurred while processing: txt.hello.The system cannot find the file specified.Error occurred while processing: worldlrow.The system cannot find the file specified.Error occurred while processing: olleh.txt.
+6  A: 

Someone had to do it eventually....

dare I ask what language this monstrosity is in?

HTML no comments :D

Hello, World<p style="display:none;">";enon:yalpsid"=elyts p<dlroW ,olleH
Russ Bradberry
+1  A: 


msgbox+"Hello, World"+y,00,y+"dlroW ,olleH"+xobgsm
Russ Bradberry
+1  A: 

sed, no comments, 51 characters:

;;s/.*\|;s/Hello, World/;q;/dlroW ,olleH/s;|\*./s;;

Give it anything as input: echo SOMETHING | sed -f thisfile.sed

The autocolorcoding looks pretty nice on this one. ☆^_^☆



alert("Hello, world");)"dlrow , olleH"(trela

I don't have time to test this out, but if I remember correctly, most browsers just stop executing the Javascript when an error occurs.

How can't you have the time? Just write "javascript:[YOUR CODE]" in the adress bar and hit enter. Besides, you're wrong, the browser first checks for syntax errors, and when any are found, the code is nort executed.
+3  A: 

PostScript, no comments, 41 chars:

(Hello, World)= quit tiuq =)dlroW ,olleH(

The interpreter stops parsing after quit ... the rest of it is syntactically ill-formed. Here's a version that runs until the end (135 characters):

[/Hello,!World/ pop 12 string/ pop cvs/ pop
dup/ pop 6 32 put/ pop = pop /tup 23 6 pop /pud
pop /svc pop /gnirts 21 pop /dlroW!,olleH/[

The fact that strings are delimited by nonidentical characters (parens) makes this a bit harder. Ironically, one can get around this by using pop in the right places; pop itself is quite coincidentally (and usefully so) a palindrome. ☆^_^☆

pop is quite a lifesaver, actually. I'm not sure how this would be possible if the operator's name weren't a palindrome. :o

Here's a slightly longer version without pop (180 chars):

12 string cvs dup 6 32 put =/nigeb>>begin/= tup 23 6 pud svc gnirts 21
+1  A: 

Golfscript - 29 bytes

"dlrow ,olleH";"Hello, World"

';' means pop and discard

Assaf Lavie
+1  A: 

Representing REBOL:

REBOL [] print "Hello world!" halt tlah "!dlrow olleH" tnirp [] LOBER


'Hello World!'['!dlroW olleH'

Easy - [ returns the left argument.

but no comments are allowed...
Assaf Lavie
@Assaf: You're right - didn't see that. Edited and now it's even shorter!