29
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ This does not seem to be "hello world". \$\endgroup\$ – Erik the Outgolfer May 18 '16 at 13:43
  • 4
    \$\begingroup\$ @ΈρικΚωνσταντόπουλος 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.) \$\endgroup\$ – Martin Ender May 18 '16 at 13:52
  • 1
    \$\begingroup\$ @MartinBüttner I think that Hello, world! and Hello World! are the only outputs allowed for a hello-world program. \$\endgroup\$ – Erik the Outgolfer May 18 '16 at 14:09

63 Answers 63

1
\$\begingroup\$

Emacs Lisp, 60 bytes

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

As you might have already guessed ; denotes a comment.

\$\endgroup\$
  • \$\begingroup\$ 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.) \$\endgroup\$ – manatwork Dec 15 '15 at 20:54
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

C, 72 bytes

main(){puts("Greetings, Planet!");}//};)"!tenalP ,sgniteerG"(stup{)(niam
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Pyth, 41 bytes

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

Prints "Greetings, Planet!", then assigns "!tenalP ,sgniteerG" to K

\$\endgroup\$
1
\$\begingroup\$

PowerShell, 41 bytes

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

Output is implied is PowerShell and anything after # is a comment.

\$\endgroup\$
1
\$\begingroup\$

R, 51 bytes

cat("Greetings, Planet!")#("!tenalP ,sgniteerG")tac

No really original, # indicates a commentary in R

\$\endgroup\$
  • \$\begingroup\$ The reversed version is )"!tenalP ,sgniteerG"(tac, not ("!tenalP ,sgniteerG")tac \$\endgroup\$ – TuxCrafting Oct 7 '16 at 13:50
1
\$\begingroup\$

Hy, 58 bytes

(print "Greetings, Planet!");;("!tenalP ,sgniteerG" tnirp)

I'm not competing.

\$\endgroup\$
0
\$\begingroup\$

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.")
\$\endgroup\$
0
\$\begingroup\$

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.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Microscript, 43 bytes

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

Microscript II, 40 bytes

Noncompeting, language postdates the question.

"!tenalP ,sgniteerG""Greetings, Planet!"
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Dyalog APL, 43 bytes

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

or

'Greetings, Planet!'∘⊣∘'!tenalP ,sgniteerG'
\$\endgroup\$
  • \$\begingroup\$ Really cute ones, but I am afraid those with braces are not palindromes as their first and last characters are different. \$\endgroup\$ – manatwork Dec 15 '15 at 20:51
  • \$\begingroup\$ @Oh, right. I'll take those away. \$\endgroup\$ – Adám Dec 16 '15 at 14:40
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

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

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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"
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Underload, 48 bytes

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

\$\endgroup\$
0
\$\begingroup\$

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!

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

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy