Ihre Aufgabe ist es, ein Programm zu erstellen, das "Greetings, Planet!" genau auf die Konsole. Scheint einfach genug, oder? Nun, hier ist der Trick. Der Code muss ein Palindrom sein, dh er liest von rechts nach links genauso wie von links nach rechts. Standardlücken sind NICHT erlaubt.
code-golf
restricted-source
hello-world
palindrome
Lirtosiast
quelle
quelle
Hello, world!
andHello World!
are the only outputs allowed for a hello-world program.Antworten:
///, 37 bytes
quelle
TI-BASIC, 67 bytes
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:
quelle
e
andi
(the numbers) to reduce byte count further?I know this is a bit late (and a bit finicky), but...
><> (Fish),
474547 Bytes (really4345, if I wasn't using the randomized direction)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 towardso
.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)
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.
quelle
Bubblegum, 38 bytes
quelle
Macaroni 0.0.2, 52 bytes
A solution that doesn't use comments. (Mostly because Macaroni doesn't have comments...)
quelle
CJam, 41 bytes
Thanks to Dennis for the three bytes off.
quelle
Foo, 39 bytes
Try it online.
quelle
!tenalP ,sgniteerG"Greetings, Planet!
saves a few bytes.JavaScript, 56 bytes
This can run in any browser.
quelle
print/tnirp
withalert/trela
, it works in other engines, too.alert`Greetings, Planet!`//`!tenalP ,sgniteerG`trela
is 52 bytesGolfScript, 41 bytes
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.
would print
quelle
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.
quelle
Python 3, 57 bytes
I fixed the issue with parenthesis.
Python 2, 53 bytes
I used advantage of the lack of required parenthesis and spaces in Python 2, but there wasn't that big of a difference.
quelle
Jelly, non-competing
25 bytes This answer is non-competing, since the challenge predates the creation of Jelly.
Look 'ma, no comments! Try it online!
How it works
quelle
Stuck, 41 Bytes
Fairly similar to the CJam answer, except in Stuck if a print command is issued, automatic stack printing is suppressed.
quelle
Mathematica, 52 bytes
Also generates a
Null "!tenalP ,sgniteerG"[tnirP]
which doesn't get printed.quelle
Echo
inv10.3
.Fission,
4543 bytesThanks to jimmy23013 for saving 2 bytes.
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.quelle
05AB1E, 16 bytes
Code:
Explanation:
Try it online!
quelle
STATA, 52 bytes
di "Greetings, Planet!"//"!tenalP ,sgniteerG" id
A slightly longer (53 byte) version that doesn't use comments is:
#d [something]
changes the delimiter (initially a carriage return) to;
unless [something] iscr
, 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.quelle
Japt, 29 bytes
This programming language was made after the question was posted, but was not made for this question.
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.
quelle
APL, 41 bytes
In APL, the last value is printed and the lamp character (⍝) start a comment.
quelle
GolfScript, 41 bytes
Try it online !
quelle
TCL, 80 Bytes
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
andcorp
. No command named}"!dlroW olleH"
has been defined, so theundefined
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.
quelle
Keg, 41 bytes
Try it online!
quelle
Vitsy, 41 Bytes
This programming language was made after the question was posted, but was not made for this question.
The
Z
character outputs everything in the stack to STDOUT.Try it online!
quelle
Unefunge 98 - 49 bytes
The code above contains two unprintable characters with code 17 (device control 1) represented by
<DC1>
.quelle
MSM, 73 bytes
The first half just before the middle
,
builds a reverse greeting string including the additionalG
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 thes
. Both,
ands
need a replacement for the left concatenation dots, hence theG
s. The,
on the right isn't executed, but build into the final string.quelle
CoffeeScript, 53 bytes
Similar to Ruby and Lua and pretty much all the variants here.
quelle
Ruby, 43 bytes
quelle
Bash,
5248 bytesAlso works in ksh, zsh, yash, dash. But not tcsh.
quelle
Lua, 52 Bytes
In Lua terminal, it is only 44 bytes with
quelle
=
in terminal, so it is 2 bytes off there. I think it existed in 2015, not sure tho.Milky Way 1.5.10,
434139 bytesExplanation
Usage
quelle