Relaxing the comment requirement a little, insert // between foo and fidne (and between endif and oof) to make it valid C++.

2009-03-26 13:28:19

"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.

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: 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).

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?

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.

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:

`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!)

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: "".

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.

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....

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):

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...

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).

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.

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