27
\$\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
  • 3
    \$\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

56 Answers 56

31
\$\begingroup\$

///, 37 bytes

Greetings, Planet!/!tenalP ,sgniteerG
\$\endgroup\$
  • 9
    \$\begingroup\$ This is gonna be tough to beat. \$\endgroup\$ – PhiNotPi Oct 3 '15 at 15:06
15
\$\begingroup\$

TI-BASIC, 67 bytes

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

This works because the last line of a program is displayed on the screen, while the first string is essentially treated as a comment.

Each lowercase letter is stored as 2 bytes, and the remaining characters are 1 byte. If I were to bend the rules and print in all caps, it would be 41 bytes:

"!TENALP ,SGNITEERG"
"GREETINGS, PLANET!"
\$\endgroup\$
  • \$\begingroup\$ Can you use e and i (the numbers) to reduce byte count further? \$\endgroup\$ – Addison Crump Oct 17 '15 at 21:37
  • 1
    \$\begingroup\$ @VTCAKAVSMoACE I considered that, but they italicized, so they look,slightly different. \$\endgroup\$ – NinjaBearMonkey Oct 18 '15 at 2:27
  • \$\begingroup\$ To be clear the first line isn't a comment, it gets stored to the answer variable. \$\endgroup\$ – Julian Lachniet Dec 29 '16 at 15:29
11
\$\begingroup\$

I know this is a bit late (and a bit finicky), but...

><> (Fish), 47 45 47 Bytes (really 43 45, if I wasn't using the randomized direction)

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

These answers are a bit different to every other; there is a chance for either direction of code to be executed.

So, by "printing to console", I assumed you meant printing to stdout. This throws an error; the error is thrown to stderr AFTER the string is printed to stdout.

To prove that this worked both ways, I used the "random direction" director, "x". Fish is a two-dimensional language, so, no matter which way the director points, the code will still (eventually) be executed.

Assuming that the first director points to the right, the characters are loaded to the "stack" in reverse order, then the reverse of the reverse (or the normal text) is printed.

Assuming that both directors point to the left, the characters are, once again, loaded to the "stack" in reverse order (because the code loads it in backwards here, direction is to the left), then the reverse of the reverse (or the normal text) is printed.

If the randomized director points up or down, this won't matter - fish knows to loop to the underside or overside of the code, pointing back to the randomizer. In this way, it will continue to loop with the randomizers until it points inward, towards the code to execute.

The !|o|! bit does the following, from both sides:

  • ! skips the next instruction (will always skip |)

  • | is a reflector; it points inward back towards o.

  • o outputs the current item of the stack to console as a character and removes it from the stack.

So, essentially, this is the "two mirrors in a bathroom pressed up together" trick, where I output until I can't anymore.

Now using a cat emoji. >o< redirects the output inward infinitely, still throwing the error, but I can get away with not using a skip into reflection.

Turns out I was right the first time - the second attempt was not palindromic, but it was reflective.

Fish (without printing to stderr), 64 Bytes (ew)

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

This dude's a little longer.

It has the same randomized arrow function (to prove it works both ways) and does not print to stderr.

The difference here is obvious; I literally print out every item in the stack, then end execution with ;.

The !; does not end execution immediately, as ! skips the next item (end exec, in this case) and continues until it hits the other side, which acts as ;!, wherein it ends execution before it skips anything.

It follows the same randomized direction pattern as the shorter answer.

\$\endgroup\$
  • \$\begingroup\$ I think you should call the language ><> to distinguish it from the Fish shell \$\endgroup\$ – Aaron Dec 7 '15 at 14:57
  • \$\begingroup\$ @Aaron It is generally assumed that Fish here means ><>, but I've encountered that problem before - I'll add it. Thanks! \$\endgroup\$ – Addison Crump Dec 7 '15 at 20:10
  • \$\begingroup\$ as i guess , it's unpridictable wheather the full code will be excuted or not . What if program counter is stuck between two random direction instructions , or just stuck at one of the random direction instructions , for example , it turns down , reachs the bottom , comes back to that instruction and start all over ? \$\endgroup\$ – user55673 Jul 13 '16 at 17:11
  • \$\begingroup\$ @GLASSIC The program will only output once, and the entire code will never be executed. \$\endgroup\$ – Addison Crump Jul 14 '16 at 3:18
10
\$\begingroup\$

Bubblegum, 38 bytes

0000000: 73 2f 4a 4d 2d c9 cc 4b 2f d6 51 08 c8 49 cc 4b 2d 51 04  s/JM-..K/.Q..I.K-Q.
0000013: 04 51 2d 4b cc 49 c8 08 51 d6 2f 4b cc c9 2d 4d 4a 2f 73  .Q-K.I..Q./K..-MJ/s
\$\endgroup\$
9
\$\begingroup\$

Macaroni 0.0.2, 52 bytes

print "Greetings, Planet!""!tenalP ,sgniteerG" tnirp

A solution that doesn't use comments. (Mostly because Macaroni doesn't have comments...)

\$\endgroup\$
  • 13
    \$\begingroup\$ Macaroni doesn't have comments? ಠ_ಠ \$\endgroup\$ – Alex A. Oct 3 '15 at 18:16
7
\$\begingroup\$

CJam, 41 bytes

Thanks to Dennis for the three bytes off.

"!tenalP ,sgniteerG";"Greetings, Planet!"
\$\endgroup\$
  • 2
    \$\begingroup\$ You need to flip the strings. Right now you're popping the right output and printing the reversed one. \$\endgroup\$ – NinjaBearMonkey Oct 3 '15 at 15:14
  • \$\begingroup\$ @NinjaBearMonkey Whoops. Fixing. \$\endgroup\$ – The_Basset_Hound Oct 3 '15 at 15:16
  • \$\begingroup\$ Also works in GolfScript. \$\endgroup\$ – Ilmari Karonen Dec 4 '15 at 20:54
7
\$\begingroup\$

Foo, 39 bytes

"Greetings, Planet!"!tenalP ,sgniteerG"

Try it online.

\$\endgroup\$
  • \$\begingroup\$ !tenalP ,sgniteerG"Greetings, Planet! saves a few bytes. \$\endgroup\$ – Dennis Apr 24 '17 at 20:17
5
\$\begingroup\$

GolfScript, 41 bytes

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

Look ma, no no-ops! Try it online in Web GolfScript.

The second half of the source code stores the string in the second string.

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

would print

Greetings, Planet!Greetings, Planet!
\$\endgroup\$
5
\$\begingroup\$

JavaScript, 56 bytes

This can run in any browser.

alert("Greetings, Planet!")//)"!tenalP ,sgniteerG"(trela
\$\endgroup\$
  • \$\begingroup\$ Replacing print/tnirp with alert/trela, it works in other engines, too. \$\endgroup\$ – ETHproductions Dec 4 '15 at 19:04
  • \$\begingroup\$ @ETHproductions can't believe I didn't think of that, thanks! \$\endgroup\$ – Downgoat Dec 5 '15 at 2:09
  • 2
    \$\begingroup\$ Template Strings? demo \$\endgroup\$ – jrich Dec 7 '15 at 21:16
  • \$\begingroup\$ @jrich your're right, alert`Greetings, Planet!`//`!tenalP ,sgniteerG`trela is 52 bytes \$\endgroup\$ – Aᴄʜᴇʀᴏɴғᴀɪʟ Feb 18 '16 at 3:51
5
\$\begingroup\$

C++, 129 bytes

Trying to do this without comments led me into a deep, dark preprocessor nightmare with no way out that I could see. Instead I've just aimed to get it as short as possible.

/**/
#include<cstdio>
int main(){puts("Greetings Planet!");}//*/
/*//};)"!tenalP sgniteerG"(stup{)(niam tni
>oidtsc<edulcni#
/**/
\$\endgroup\$
4
\$\begingroup\$

Stuck, 41 Bytes

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

Fairly similar to the CJam answer, except in Stuck if a print command is issued, automatic stack printing is suppressed.

\$\endgroup\$
4
\$\begingroup\$

Python 3, 57 bytes

print('Greetings, Planet!')#)'!tenalP ,sgniteerG'(tnirp

I fixed the issue with parenthesis.

Python 2, 53 bytes

print'Greetings, Planet!'#'!tenalP ,sgniteerG'tnirp

I used advantage of the lack of required parenthesis and spaces in Python 2, but there wasn't that big of a difference.

\$\endgroup\$
4
\$\begingroup\$

Jelly, non-competing

25 bytes This answer is non-competing, since the challenge predates the creation of Jelly.

»1ị“RsẈḄ,#ʠU“Uʠ#,ḄẈsR“ị1»

Look 'ma, no comments! Try it online!

How it works

»1ị“RsẈḄ,#ʠU“Uʠ#,ḄẈsR“ị1»  Main link. No arguments.

   “        “        “  »  Decompress all three strings; yield a list of strings.
    RsẈḄ,#ʠU               (decompresses to 'Greetings, Planet!')
             Uʠ#,ḄẈsR      (decompresses to ' WafdkmC Posited,')
                      ị1   (decompresses to 'Taarhus')

»1                         Take the maximum of the default argument (0) and 1.
  ị                        Select the string at the index to the left.
\$\endgroup\$
3
\$\begingroup\$

Mathematica, 52 bytes

Print@"Greetings, Planet!""!tenalP ,sgniteerG"@tnirP

Also generates a Null "!tenalP ,sgniteerG"[tnirP] which doesn't get printed.

\$\endgroup\$
  • 1
    \$\begingroup\$ FYI, a lot of your answers (this one included) have been getting tossed in the Low Quality queue because they're solely a title/score and code. Though there's nothing wrong with that, you may consider adding more text (such as an explanation) so they don't get auto-flagged. \$\endgroup\$ – Mego Nov 29 '15 at 2:57
  • \$\begingroup\$ @Mego Okay, thought they were pretty self-explanatory. \$\endgroup\$ – LegionMammal978 Nov 29 '15 at 11:14
  • \$\begingroup\$ I'm not saying the lack of an explanation is a bad thing (though answers with explanations tend to get more upvotes), I'm just letting you know that your (valid) answers were getting auto-flagged because of their length. :) \$\endgroup\$ – Mego Nov 30 '15 at 9:12
  • 2
    \$\begingroup\$ you can save 2 bytes with Echo in v10.3. \$\endgroup\$ – shrx Dec 7 '15 at 13:46
3
\$\begingroup\$

Fission, 45 43 bytes

Thanks to jimmy23013 for saving 2 bytes.

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

Try it online!

R initialises an atom which moves to the right. " toggles string mode which simply prints the desired string to STDOUT before hitting ;, which destroys the atom and terminates the program. The first half is simply never executed.

\$\endgroup\$
  • \$\begingroup\$ @jimmy23013 I have no clue, to be honest. Thanks. \$\endgroup\$ – Martin Ender May 18 '16 at 13:47
2
\$\begingroup\$

STATA, 52 bytes

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

A slightly longer (53 byte) version that doesn't use comments is:

#d
di "Greetings, Planet!";"!tenalP ,sgniteerG" id
d#

#d [something] changes the delimiter (initially a carriage return) to ; unless [something] is cr, so the first command changes the delimiter to ;, the second prints the string, and the third (which continues until the end) is apparently a nop, though I have no idea why. I would have guessed that this would throw an error (unrecognized command "!tenalP ,sgniteerG" or something), but apparently not.

\$\endgroup\$
2
\$\begingroup\$

Japt, 29 bytes

This programming language was made after the question was posted, but was not made for this question.

`!t?ÓP ,?Ä>ÎG`;`GÎ>Ä?, PÓ?t!`

Try it online!

Each ? is an unprintable Unicode char: U+0082, U+000F, U+000F, and U+0082, respectively.

Fun fact: If Japt had been published a month sooner, it would have legitimately won this challenge.

\$\endgroup\$
2
\$\begingroup\$

APL, 41 bytes

'Greetings, Planet!'⍝'!tenalP ,sgniteerG'

In APL, the last value is printed and the lamp character (⍝) start a comment.

\$\endgroup\$
  • \$\begingroup\$ Hello, and welcome to PPCG! Great answer! \$\endgroup\$ – NoOneIsHere May 28 '16 at 20:20
2
\$\begingroup\$

GolfScript, 41 bytes

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

Try it online !

\$\endgroup\$
  • \$\begingroup\$ @muddyfish Edited. Now it is a palindrome . Sorry. \$\endgroup\$ – Lordmusic Player May 31 '16 at 20:19
2
\$\begingroup\$

TCL, 80 Bytes

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

explanation: TCL executes a global proc unknown when it encounters a call to an undefined command, the first line redefines that proc to a simple "hello world" program.

TCL's quoting rules are quite subtle, an open brace starts a quoted word that extends to the next matching close brace, allowing nested, quoted words. Braces are otherwise treated as normal characters. five words: }"!dlroW olleH", stup{, sgra, nwonknu and corp. No command named }"!dlroW olleH" has been defined, so the undefined proc from the first line is invoked instead.

A similar question was posted on the StackOverflow of antiquity; which has since been closed and deleted. I used my solution as a tongue in cheek TCL sample in this answer, and am now getting comments asking for an explanation, so I recreate my answer here.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 16 bytes

Code:

”!º¥,ÁÙ””ÙÁ,¥º!”

Explanation:

”!º¥,ÁÙ”          # Compressed string which results in "! Crm, Everywhere".
        ”ÙÁ,¥º!”  # Compressed string which results in "Greetings, Planet!".
                  # Top of stack is implicitly outputted.

Try it online!

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

Vitsy, 41 Bytes

This programming language was made after the question was posted, but was not made for this question.

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

The Z character outputs everything in the stack to STDOUT.

Try it online!

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

Unefunge 98 - 49 bytes

"!tenalP ,sgniteerG<DC1>"k,@,k"<DC1>Greetings, Planet!"

The code above contains two unprintable characters with code 17 (device control 1) represented by <DC1>.

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

MSM, 73 bytes

GGreetings, Planet!.................,.................!tenalP ,sgniteerGG

The first half just before the middle , builds a reverse greeting string including the additional G on the very right. The middle , drops it and the rest is a canonical "Hello/Greeting/whatever" program. The additional characters on both ends are needed, because the message contains a ,. The left one is executed and drops the s. Both , and s need a replacement for the left concatenation dots, hence the Gs. The , on the right isn't executed, but build into the final string.

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

CoffeeScript, 53 bytes

Similar to Ruby and Lua and pretty much all the variants here.

alert 'Greetings, Planet!'#'!tenalP ,sgniteerG' trela
\$\endgroup\$
1
\$\begingroup\$

Ruby, 43 bytes

p"Greetings, Planet!"#"!tenalP ,sgniteerG"p
\$\endgroup\$
1
\$\begingroup\$

Lua, 52 Bytes

print"Greetings, Planet!"--"!tenalP ,sgniteerG"tnirp

In Lua terminal, it is only 44 bytes with

="Greetings, Planet!"--"!tenalP ,sgniteerG"=
\$\endgroup\$
  • \$\begingroup\$ My bad. Thanks for the alert! \$\endgroup\$ – Digital Veer Nov 29 '15 at 2:30
  • \$\begingroup\$ Remove all parentheses. For functions with a single string parameter they are optional. \$\endgroup\$ – manatwork Dec 5 '15 at 11:13
1
\$\begingroup\$

Milky Way 1.5.10, 43 41 39 bytes

"Greetings, Planet!"!tenalP ,sgniteerG"

Explanation

"Greetings, Planet!"                       # push the string to the stack
                    !                      # output the TOS
                     tenalP ,sgniteerG"    # throws an error and exits

Usage

python3 milkyway.py <path-to-code>
\$\endgroup\$
  • \$\begingroup\$ Did you really need a comment? If this is stack based (without implicit output), then just outputting the stack should work. \$\endgroup\$ – Addison Crump Dec 7 '15 at 20:15
  • \$\begingroup\$ You're right! Thanks. @FlagAsSpam \$\endgroup\$ – Zach Gates Dec 7 '15 at 20:25
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\$

Your Answer

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