# Palindrome Hello, World

Your task is to create a program that prints "Greetings, Planet!" exactly to the console. Seems simple enough, right? Well, here's the trick. The code must be a palindrome, meaning it reads from right to left the same as in left to right. Standard loopholes are NOT allowed.

• This does not seem to be "hello world". – Erik the Outgolfer May 18 '16 at 13:43
• @ΈρικΚωνσταντόπουλος It's the same as Hello World for all intents and purposes. The goal is to print a short string consisting of two words with the punctuation common in Hello World programs as well. Apart from built-ins that print Hello World, solutions will be absolutely identical (apart from the actual string) regardless of the actual string being printed. (And I assume the phrase "Greetings, Planet!" was chosen specifically to make built-ins useless.) – Martin Ender May 18 '16 at 13:52
• @MartinBüttner I think that Hello, world! and Hello World! are the only outputs allowed for a hello-world program. – Erik the Outgolfer May 18 '16 at 14:09

# Emacs Lisp, 60 bytes

(message"Greetings, planet!");)"!tenalp , sgniteerG"egassem(


As you might have already guessed ; denotes a comment.

• There you have some characters images reversed instead of character orders. For example if the first character is (, the last one must also be (. (See Downgoat's JavaScript answer as example.) – manatwork Dec 15 '15 at 20:54

# jq, 44 characters

(42 charactes code + 2 character command line option.)

"Greetings, Planet!"//"!tenalP ,sgniteerG"


(Not a big deal, posted just for the sake of that operator. Yes, // is not comment, is the alternative operator: if its left operand is null or false, the right operand is returned, otherwise the left operand.)

Sample run:

bash-4.3$jq -nr '"Greetings, Planet!"//"!tenalP ,sgniteerG"' Greetings, Planet!  On-line test (Passing -r through URL is not supported – check Raw Output yourself.) # Golfscript, 41 bytes "!tenalP ,sgniteerG";"Greetings, Planet!" Pushes "!tenalP ,sgniteerG" to stack, removes top of stack (;), and pushes "Greetings, Planet!". Stack is printed at end of execution in GolfScript. # Self-Modifying Brainf*ck, 67 bytes +[<[<]<[.<]-][0Greetings, Planet!0!tenalP ,sgniteerG0][-[>.]>[>]>]+  Where the 0's denote null characters. The first <[<] moves the pointer to the beginning of the message (the last null character) And the following <[,<] reads and outputs the message until the terminating null character. This is a pretty long answer, so it probably won't stand a chance, but hey, it's pretty cool. # C, 72 bytes main(){puts("Greetings, Planet!");}//};)"!tenalP ,sgniteerG"(stup{)(niam  # Fishing, Dock length 41 v+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC Greetings, Planet!P!tenalp ,sgniteerG  For a palindrome that also includes the dock and is measured in total bytes, this has 132 bytes. v+CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC Greetings, Planet!P!tenalp ,sgniteerG CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC+v  Fishing prints the stack with P. Because the dock ends at the end of the first line, no other fish are caught or executed. # Fuzzy Octo Guacamole, 52 bytes (non-competing, FOG is newer than the challenge) 'Greetings, Planet!'X@X'!tenalP ,sgniteerG'  Pushes "Greetings, Planet!" to the stack, pop, print, and end. ('' pushes the string, _; pops and prints, and @ terminates immediately. Without the @, it would then print 0 after the string. ## Self-modifying Brainfuck, 47 bytes Greetings, Planet!<[.<]<.[<!tenalP ,sgniteerG  The code contains two null-bytes, shown here as 0: Greetings, Planet0!<[.<]<.[<!0tenalP ,sgniteerG  Try it online! ### Explanation Like the other SMBF answers, this includes the required string in the source code, along with a null-byte as an end-of-string marker. Note that SMBF is like regular BF, except that the source is copied to the front of the tape and the tape head starts at the cell just after the source code. We can save some bytes over the other answers by putting the actual string at the end, so that we don't have to skip past the actual source code. Finally, we can save one more byte by putting the ! on the other side of the null-byte which conveniently lets us reuse the <. in the mirror image to print the last character (otherwise we'd have to double the ] to avoid that <. is executed). Here is the code: , Read a character, which is a no-op with no input. < Move tape head onto the 'G'. [.<] In a loop, print character, move tape head left. This prints the desired string except for the '!'. The loop terminates when the tape head reaches the null byte. < Move the tape head left another cell onto the '!'. . Print it. [ Unmatched square bracket, terminates the program.  ## Hoon, 41 bytes "Greetings, Planet!":"!tenalP ,sgniteerG"  In Hoon, a:b means "compute a in the context of b". To include a library, for example, you stick a rune that evaluates the rest of your program in the context of the core containing the library. This is possible because cores also contain the entire kernel and stdlib, so you can nest them and still compute. Because a string literal is just a constant expression that doesn't depend on the context it is being evaluated in at all, we can replace the entire stdlib with just another constant expression and it will evaluate to the same thing. # Brachylog, 41 bytes (non-competing) "Greetings, Planet!"w"!tenalP ,sgniteerG"  This will call w - write with "Greetings, Planet!" as input and "!tenalP ,sgniteerG" as output. w writes its input to STDOUT and does nothing with its output. # Pyth, 41 bytes "Greetings, Planet!"K"!tenalP ,sgniteerG"  Prints "Greetings, Planet!", then assigns "!tenalP ,sgniteerG" to K # PowerShell, 41 bytes "Greetings, Planet!"#"!tenalP ,sgniteerG"  Output is implied is PowerShell and anything after # is a comment. # R, 51 bytes cat("Greetings, Planet!")#("!tenalP ,sgniteerG")tac  No really original, # indicates a commentary in R • The reversed version is )"!tenalP ,sgniteerG"(tac, not ("!tenalP ,sgniteerG")tac – TuxCrafting Oct 7 '16 at 13:50 # Hy, 58 bytes (print "Greetings, Planet!");;("!tenalP ,sgniteerG" tnirp)  I'm not competing. # Mouse-2002, 47 bytes "Greetings, Planet"33!'$'!33"tenalP ,sgniteerG"


I hate that I have to print !'s charcode because using it in a string just prints \n.

things_to_fix_in_my_mouse_reboot.append("EXCLAMATION POINTS ARE THEMSELVES, NOT NEWLINES.")


# PlatyPar, 40 bytes

"!tenalp ,sgniteerG""Greetings, planet!"


Pushes the two strings to the stack. At the end of the program, the last item of the stack is printed, so the first inverted one is ignored. I see a lot of other answers like this, except mine doesn't have something between the two strings.

# Microscript, 43 bytes

"!tenalP ,sgniteerG"aha"Greetings, Planet!"


# Microscript II, 40 bytes

Noncompeting, language postdates the question.

"!tenalP ,sgniteerG""Greetings, Planet!"


# Pylongolf, 43 bytes

."Greetings, Planet!"~"!tenalP ,sgniteerG".


~ prints the stack nicely, . resets the stack.
"Greetings, Planet!" pushes the sentence into the stack, ~ prints it.
The rest is a blur.

EDIT: I saved 2 bytes by removing the ~ symbols on both sides.

# Dyalog APL, 43 bytes

'!tenalP ,sgniteerG'∘⊢∘'Greetings, Planet!'


or

'Greetings, Planet!'∘⊣∘'!tenalP ,sgniteerG'

• Really cute ones, but I am afraid those with braces are not palindromes as their first and last characters are different. – manatwork Dec 15 '15 at 20:51
• @Oh, right. I'll take those away. – Adám Dec 16 '15 at 14:40

# Haystack, 43 bytes

"Greetings, Planet!"o|o"!tenalP, sgniteerG"


Here's how this two-dimensional program works:

• "Greetings, Planet!" pushes a string whose content is Greetings, Planet! to the stack.
• o prints everything in the stack.
• | is the needle. The program ends because it found the needle in the haystack!
• o"!tenalP, sgniteerG" isn't executed as the needle is found before reaching there.

Hello World example(s) from shebang

## INXW63CTMNZGS4DU, 42 bytes

"Greetings, Planet!"#"!tenalP, sgniteerG"


A trailing newline is needed at the end

The # character start a comment, and the last value is printed, so this program print "Greetings, Planet!"

# Java, 170 164 bytes

interface e{static void main(String[]s){System.out.print("Greetings, Planet!");}}//}};)"!tenalP ,sgniteerG"(trinp.tuo.metsyS{)s][gnirtS(niam diov citats{e ecafretni


# PHP, 48 52 bytes

echo"Greetings, Planet!";//;"!tenalP ,sgniteerG"ohce


// comments out the rest of the line, leaving echo"Greetings, Planet!";.
No space is needed between echo and ", meaning this is this the shortest possible response for PHP.

Would have loved a clever excuse to use /* */, but couldn't think of one.

• surely you need to add ohce to the end? – user5957401 Aug 9 '16 at 19:52
• Right you are, no idea how I missed that. – ricdesi Aug 10 '16 at 14:21

# Nim, 49 bytes

echo"Greetings, Planet!"#"!tenalP ,sgniteerG"ohce


Pretty self-explanatory. Uses Nim's short echo syntax and a comment to create the palindrome.

## Straw, 41 bytes

(Greetings, Planet!)>)!tenalP ,sgniteerG(


Try it online

(Greetings, Planet!) push a string on the stack, > print it. The rest of the program simply fill the stack with junk.

## AWK, 66 bytes

BEGIN{print"Greetings, Planet!"#"!tenalP, sgniteerG"tnirp{NIGEB


Could save some bytes if input were allowed, but I assume it isn't.

The input required code would save 15 bytes and be run like this:

awk '{\$0="Greetings, Planet!"}1#1{"!tenalP, sgniteerG"{' <<< "arbitrary string here"


# q/kdb+ 41 bytes

Solution:

"!tenalP ,sgniteerG";"Greetings, Planet!"


Example:

q)"!tenalP ,sgniteerG";"Greetings, Planet!"
"Greetings, Planet!"


Explanation:

This is really just two statements separated by a semicolon, "!tenalP ,sgniteerG" and "Greetings, Planet!", due to the ;, the first statement does not get printed to the console.

)(Greetings, Planet!)S())(S)!tenalP ,sgniteerG()


Uses the fact that non-matching closing brackets don't error on the interpreter that TIO uses.

# How it works

) Used to make a matching pair of brackets at the end, so it doesn't error
(Greetings, Planet!)S   Outputs 'Greetings, Planet!'
()   Used to make it so the output command doesn't run a second time, since it gets enclosed in bracket. Also, adds an element to the stack so the 'a' in the '!tenalP, sgniteerG', doesn't error, since 'a' is a command in Underload
)(S)   Pushes S to the stack
!tenalP ,sgniteerG   Reversed 'Greetings, Planet'. Every character is a no-op apart from 'a'
()   Matching pair of brackets I mentioned on the first line


Try it Online!

# Java, 192 Bytes

public class C{public static void main(String[] args){System.out.print("Greetings, Planet!");}}//}};)"!tenalP ,sgniteerG"(tnirp.tuo.metsyS{)sgra ][gnirtS(niam diov citats cilbup{C ssalc cilbup


For the online compiler i had to change the class name from C to Main

Try it online!

• In what Java compiler does this work as-is, without changing C to Main? – mbomb007 Aug 1 '19 at 14:45
• this is necessary for the online compiler but i dont know why – René Aug 1 '19 at 15:07
• Does it work in an offline compiler? – mbomb007 Aug 1 '19 at 15:59
• yeah of cause it does – René Aug 1 '19 at 16:05

# T-SQL, 52 bytes

PRINT'Greetings, Planet!'--'!tenalP ,sgniteerG'TNIRP


Not much different from other answers, but didn't see another SQL-based solution.

-- is an in-line comment in T-SQL, PRINT is one byte shorter than SELECT.