146
\$\begingroup\$

Write a program that prints "Hello, World!". But also, if you take only the first, third, fifth, etc. characters of your program, the resulting program should still print "Hello, World!".

If your program is:

abc
def

It should output "Hello, World!", but so should

acdf

No solutions with fewer than 2 characters.

\$\endgroup\$
15
  • 3
    \$\begingroup\$ Can there be whitespace around the output? \$\endgroup\$ Commented Jun 26, 2017 at 20:20
  • 24
    \$\begingroup\$ Amazing first post! \$\endgroup\$
    – Adám
    Commented Jun 26, 2017 at 22:49
  • 13
    \$\begingroup\$ Seeing all the answers with "HHeelllloo" reminded me of speaking Whale. \$\endgroup\$ Commented Jun 27, 2017 at 4:19
  • 36
    \$\begingroup\$ Pro tip for avoiding "Hello, World!" built-ins in challenges like this: use a slightly different string of similar complexity like "Greetings, Earthlings!" \$\endgroup\$ Commented Jun 27, 2017 at 7:15
  • 7
    \$\begingroup\$ "No solutions with fewer than 2 characters." Amazing. \$\endgroup\$
    – Rob Grant
    Commented Jun 28, 2017 at 9:10

92 Answers 92

214
\$\begingroup\$

Python 3, 61 bytes

rant="partisn't"
print(("HHeelllloo,,  WWoorrlldd!!"""[::2]))

Try it online!

Abusing the fact that print is a function in Python 3 :)

The least partisan solution you'll find here on PPCG.

Becomes

rn=print
rn("Hello, World!"[:])
\$\endgroup\$
9
  • 52
    \$\begingroup\$ This is beautiful. \$\endgroup\$ Commented Jun 26, 2017 at 22:30
  • 1
    \$\begingroup\$ @musicman523 But, Doesn't REPL surround the text with single-quotes in that case. \$\endgroup\$
    – 0xffcourse
    Commented Jun 27, 2017 at 2:38
  • 1
    \$\begingroup\$ @officialaimm Yes, I suppose it does \$\endgroup\$ Commented Jun 27, 2017 at 3:25
  • 1
    \$\begingroup\$ @yamboy1 Try deleting every other letter \$\endgroup\$ Commented Jun 27, 2017 at 3:49
  • 2
    \$\begingroup\$ This is art. This made me cry. \$\endgroup\$ Commented Jul 20, 2017 at 12:47
62
\$\begingroup\$

Cardinal, 29 bytes

%
"
H
e
l
l
o
,
 
W
o
r
l
d
!

Try it online!

Removing every other character removes all the linefeeds, which still results in Hello, World!:

%"Hello, World!

Try it online!

The reason this works is that % creates four instruction pointers, moving in each of the four cardinal directions. IPs that leave the source code are simply removed. So in the first case, only the south-going IP remains and in the second case, only the east-going IP remains, all the others are simply dropped. In either case, the executed program is then just "Hello, World!. The " toggles to string mode where each cell is simply printed to STDOUT. We don't need to terminate the string, because leaving the source code still terminates the program.

Note that the same idea works in Beeswax, using * instead of % and ` instead of " (this is because Beeswax was largely inspired by Cardinal but uses a hexagonal grid).

Try it online! (vertical) | | Try it online! (horizontal)

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

C, 125 bytes

xpxuxtxs( ) { }xuxs ( ) { } main( ) {puts ( "Hello, World!" ) ; } mxaxixn ( ) {xpxuxtxs ( " H e l l o ,   W o r l d ! " ) ; }

Try it online!

With even characters removed:

xxxx(){}us(){}mi(){us("el,Wrd");}main(){puts("Hello, World!");}

Try it online!

\$\endgroup\$
37
\$\begingroup\$

Actually, 2 bytes

HH

Explanation:

H, as you might expect, pushes Hello, World! to the stack.

The main program (HH) will encounter the first H and push Hello, World! to the stack. On the second H, however, it will try to use two arguments (as the stack needs to be empty to push Hello, World!) and fail. However, this error will be ignored and then Hello, World! will be implicitly printed.

The second program (H) will push Hello, World! once, and that will be impliclty printed.

This is similar to Fatalize's 2-byte answer, but this doesn't really "cheat".

Try it online!

\$\endgroup\$
5
  • 4
    \$\begingroup\$ Nice solution, but I think this shouldn't count since it's too much like a one-character solution. \$\endgroup\$
    – pommicket
    Commented Jun 26, 2017 at 20:54
  • 32
    \$\begingroup\$ @LeoTenenbaum Why not? It conforms to the rules perfectly fine. \$\endgroup\$
    – Okx
    Commented Jun 26, 2017 at 21:06
  • 2
    \$\begingroup\$ What you explain isn't the case, H would only push Hello, World! on an empty stack, and if the stack isn't empty, it would expect 2 arguments, so there will be an error, and errors are ignored. And no Actually doesn't implicitly print only the topmost element. \$\endgroup\$ Commented Jun 27, 2017 at 7:30
  • \$\begingroup\$ @EriktheOutgolfer Oops. Will fix. \$\endgroup\$
    – Okx
    Commented Jun 27, 2017 at 9:37
  • \$\begingroup\$ This is why Actually is my favorite golfing language. It's at the perfect level of stupid. \$\endgroup\$
    – RShields
    Commented Jul 3, 2017 at 0:07
24
\$\begingroup\$

Lua, 89 bytes

--- [ [
print("Hello, World!")
--[[ ] ]
pCrAiLnCtU(L"AHTeOlRlFoE,L IWNoEr:lDd !:"D)
---]]

Try it online! As the syntax highlighting shows, this is massive comment abuse.

Alternate:

--[[pit"el,Wrd"
-[]]print("Hello, World!")--]

Try it online!

And for convenience, a program to convert a program into every other character form: Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ I like this one! The commenting format of Lua seems similar to T-SQL, I'm going to try and work on one for that language. \$\endgroup\$
    – BradC
    Commented Jun 26, 2017 at 21:11
  • 3
    \$\begingroup\$ This sort of trick should work for any language with both block comments and line comments (C, JS, etc) \$\endgroup\$ Commented Jun 26, 2017 at 21:25
  • 2
    \$\begingroup\$ CALCULATORFELINE:D :D \$\endgroup\$
    – Riking
    Commented Jun 28, 2017 at 1:50
  • 3
    \$\begingroup\$ HHeelllloo WWoorrlldd!! is kinda boring :P \$\endgroup\$ Commented Jun 28, 2017 at 15:34
21
\$\begingroup\$

Retina, 39 bytes


HHeelllloo,,  WWoorrlldd!!


(.).x?
$1

Try it online!

Taking every other character gives:


Hello, World!
()x
1

Try it online!

The first program creates a string with the greeting duplicated. Then it replaces each pair of characters with the first character. There is also an empty stage that replaces all empty strings with empty strings in between, but that doesn't do anything. The second program fails to match the letter "x" so it doesn't replace anything after creating the greeting.

Perhaps more amusingly, if the third stage is changed slightly the first set of characters doesn't have to be the same message. This could lead to many identical length solutions such as full and halved.

\$\endgroup\$
19
\$\begingroup\$

Charcoal, 25 bytes

H→e→l→l→o→,→ →W→o→r→l→d→!

Try it online!

If you remove the even characters, you just remove the arrow commands that indicate the direction of the next text, and that leaves the following code:

Hello, World!

Try it online!

That also prints the greeting.

\$\endgroup\$
18
\$\begingroup\$

Haskell, 85 bytes

{--}main=putStr"Hello, World!"--} m a i n = p u t S t r " H e l l o ,   W o r l d ! "

Try it online!

Every second character removed:

{-mi=uSrHlo ol!-}main=putStr"Hello, World!"

Try it online!

This exploits the two comment formats in Haskell: {- -} for in-line or multi-line comments and -- to comment the rest of the line.

\$\endgroup\$
18
\$\begingroup\$

Javascript, 67 bytes

/**/alert`Hello, World`// * / a l e r t ` H e l l o ,   W o r l d `

Every second letter removed:

/*aetHlo ol`/*/alert`Hello, World`

Just like many other answers, this exploits comments.

\$\endgroup\$
1
  • \$\begingroup\$ Nice answer, +1! Saved 2 bytes by creating a port of your answer in my Java 8 answer, and an additional byte when I changed // * / to //**/ (which unfortunately isn't possible in your case due to /**/alert`Hello, World` being an odd amount of bytes, instead of even like in my case. \$\endgroup\$ Commented Jun 27, 2017 at 9:54
15
\$\begingroup\$

Brachylog, 4 bytes

Ḥ~wḤ

Try it online!

Explanation

~w writes its right variable to STDOUT, and ignores its left argument. is "Hello, World!", so this prints Hello, World!.

If we only take the first and third chars, we get Ḥw. In that case w writes its left variable and ignores its right variable, so it also prints Hello, World!.

2 bytes

ḤḤ

Try it online!

This is technically a valid answer, but this unifies the output variable of the program instead of printing to STDOUT, so I guess the 4 bytes program is more in the spirit of the challenge.

\$\endgroup\$
6
  • \$\begingroup\$ I do not think the 2 byte answer is 'technically' valid, as the challenge states print. \$\endgroup\$
    – Okx
    Commented Jun 26, 2017 at 21:56
  • 1
    \$\begingroup\$ @Okx print, as in onto a piece of paper? \$\endgroup\$
    – user36219
    Commented Jun 27, 2017 at 10:39
  • \$\begingroup\$ @theonlygusti It means print to STDOUT. \$\endgroup\$
    – Okx
    Commented Jun 27, 2017 at 10:40
  • 5
    \$\begingroup\$ @theonlygusti Sigh... that's what's meant by print by default. \$\endgroup\$
    – Okx
    Commented Jun 27, 2017 at 10:42
  • 5
    \$\begingroup\$ @Okx you're trying to be pedantic to invalidate a solution, but actually there's nothing invalid about it. The challenge only says "output." \$\endgroup\$
    – user36219
    Commented Jun 27, 2017 at 10:43
15
\$\begingroup\$

x86 machine code, 162 bytes

demo

PROG.COM Download and run it in MS-DOS emulator, DOSBox for example.

90 B3 B4 B4 02 90 90 B3 B2 B2 48 90 90 B3 CD CD 21 90 90 B3 B2 B2 65 90 
90 B3 CD CD 21 90 90 B3 B2 B2 6C 90 90 B3 CD CD 21 90 90 B3 CD CD 21 90 
90 B3 B2 B2 6F 90 90 B3 CD CD 21 90 90 B3 B2 B2 2C 90 90 B3 CD CD 21 90 
90 B3 B2 B2 20 90 90 B3 CD CD 21 90 90 B3 B2 B2 77 90 90 B3 CD CD 21 90 
90 B3 B2 B2 6F 90 90 B3 CD CD 21 90 90 B3 B2 B2 72 90 90 B3 CD CD 21 90 
90 B3 B2 B2 6C 90 90 B3 CD CD 21 90 90 B3 B2 B2 64 90 90 B3 CD CD 21 90 
90 B3 B2 B2 21 90 90 B3 CD CD 21 90 90 B3 CD CD 20 90

after removal MINI.COM Download

90 B4 02 90 B2 48 90 CD 21 90 B2 65 90 CD 21 90 B2 6C 90 CD 21 90 CD 21 
90 B2 6F 90 CD 21 90 B2 2C 90 CD 21 90 B2 20 90 CD 21 90 B2 77 90 CD 21 
90 B2 6F 90 CD 21 90 B2 72 90 CD 21 90 B2 6C 90 CD 21 90 B2 64 90 CD 21 
90 B2 21 90 CD 21 90 CD 20

How to run?

Install DOSBox, for Ubuntu/Debian

sudo apt install dosbox

Run it

dosbox

In DOSBOX

mount c /home/user/path/to/your/directory
c:
PROG.COM
MINI.COM

How does it works?

Machine operation codes represents assembly language instructions.

In MS-DOS to print char you will set registers and make interrupt. AH register will be 0x02, DL register contains your char. Interrupt vector is 0x21.

mov ah,0x2  ;AH register to 0x2 (B4 02)
mov dl,0x48 ;DL register to "H" (B2 48)
int 0x21    ;0x21 interrupt     (CD 21)

MS-DOS COM file tiny model is good choise, because it doesn't have any headers. It is limited by 64K, but in our case it doesn't matters.

To stop program use 0x20 interrupt

int 0x20    ;0x20 interrupt     (CD 20)

Magic

If you want to execute 0xAB opcode command with one parameter 0xCD, you write

AB CD

In PROG.COM

90 B3 AB AB CD 90
nop         ; No operation (90)
mov bl,0xb4 ; BL register to AB (B3 AB)
AB CD command (AB CD)
nop         ; No operation (90)

In MINI.COM

90 AB CD
nop         ; No operation (90)
AB CD command (AB CD)

It is equal machine codes, if you don't use BL register.

Generator

Convert text file with hex to hex binary

cat hex_file | xxd -r -p > exec.com

function byte2hex(byte){
	var ret=byte.toString(16).toUpperCase();
	return ret.length==1 ? "0"+ret : ret;
}

function str2hex(str){
	var ret = [];
	for(var i=0;i<str.length;i++){
		ret.push(byte2hex(str.charCodeAt(i)));
	}
	return ret;
}

function genCode(hexArr){
	var ret = [["B4","02"]];
	for(var i=0;i<hexArr.length;i++){
		if(hexArr[i]!=hexArr[i-1]){
			ret.push(["B2",hexArr[i]]);
		}
		ret.push(["CD","21"]);
	}
	ret.push(["CD","20"]);

	return ret;
}


function magicCode(str){
	var ret=[""];
	var code=genCode(str2hex(str));

	for(var i=0;i<code.length;i++){
		ret.push("90 B3 "+code[i][0]+" "+code[i][0]+" "+code[i][1]+" 90");
		if(i%4==3){ret.push("\n");}
	}
	return ret.join(" ");
}

function magicCodeMinified(str){
	var ret=[""];
	var code=genCode(str2hex(str));

	for(var i=0;i<code.length;i++){
		ret.push("90 "+code[i][0]+" "+code[i][1]);
		if(i%8==7){ret.push("\n");}
	}
	return ret.join(" ");
}

var str=prompt("string","Hello, world!");
var out="PROG.COM\n" + magicCode(str)+"\n\nMINI.COM\n"+magicCodeMinified(str);

document.write(out.replace("\n","<br>"));
alert(out);

\$\endgroup\$
2
  • \$\begingroup\$ Remove all ` 90 90` for -52 bytes. \$\endgroup\$
    – Maya
    Commented Dec 22, 2018 at 19:37
  • \$\begingroup\$ Also the nop at the very end will never be reached. \$\endgroup\$
    – Maya
    Commented Dec 22, 2018 at 20:00
11
\$\begingroup\$

Haskell, 102 bytes

The full program:

main= putStr"Hello, World!";;
putSt   x ="p u t S t r  \" H e l l o ,   W o r l d !\"";
mmaaiin = main

and with every other character removed:

mi=ptt"el,Wrd";ptt x=putStr "Hello, World!";main=mi
\$\endgroup\$
1
  • \$\begingroup\$ You can take off 2 bytes by removing the spaces between p u t S t r and \". \$\endgroup\$
    – Wheat Wizard
    Commented Feb 16, 2018 at 19:54
10
\$\begingroup\$

Pyth, 31 bytes

p% 2"HHeelllloo,,  WWoorrlldd!!

Try it online!

Becomes

p "Hello, World!

Thanks to @CalculatorFeline for pointing out an error and removing one byte.

\$\endgroup\$
2
  • \$\begingroup\$ Characters kept start from the first, not the second. You can drop the leading space. \$\endgroup\$ Commented Jun 26, 2017 at 20:54
  • \$\begingroup\$ Ah, thanks @CalculatorFeline. I read "Take" as "Remove" in the spec. \$\endgroup\$ Commented Jun 26, 2017 at 20:55
8
\$\begingroup\$

V, 32 bytes

i;H;e;l;l;o;,; ;w;o;r;l;d;!;<esc>;Ó;

Note that <esc> is a single character, e.g. 0x1b

Try it online!

Removing every other character gives:

iHello, world!<esc>Ó

Try it online!

\$\endgroup\$
8
\$\begingroup\$

PHP, 53 bytes

#
echo date(
$e_c_h_o='\H\e\l\l\o\,\ \W\o\r\l\d\!
');

With every other character removed:

#eh ae
echo'Hello, World!';
\$\endgroup\$
0
8
\$\begingroup\$

Jelly, 26 25 bytes

““3ḅaė;œ»ḷ“ 3 ḅ a ė ; œ »

Try it online!

After removing every second character, we're left with the following code.

“3a;»“3ḅaė;œ»

Try it online!

How it works

““3ḅaė;œ»ḷ“ 3 ḅ a ė ; œ »  Main link.

““3ḅaė;œ»                  Index into Jelly's dictionary to yield
                           ["", "Hello, World!"]. 
          “ 3 ḅ a ė ; œ »  Index into Jelly's dictionary to yield.
                          " FullERebitingBEfluffiest adoptable".
         ḷ                 Take the left result.
“3a;»“3ḅaė;œ»  Main link.

“3a;»          Index into Jelly's dicrionary to yield " N-".
               Set the argument and the return value to the result.
     “3ḅaė;œ»  Index into Jelly's dicrionary to yield "Hello, World!".
               Set the return value to the result.
\$\endgroup\$
8
+100
\$\begingroup\$

Cubically v2.1, 222 bytes

+0503 @@6 :22 //1 +050501 @@6 :55 +0502 @@6@6 :33 //1 +050502 @@6 :55 +03 //1 +04 @@6 :55 //1 +03 @@6 :55 +01 //1 +0504 @@6 :33 //1 +050502 @@6 :55 +01 //1 +050502 @@6 :55 +0502 @@6 :11 //1 +050501 @@6 :55 +01 //1 +03 @@6

Try it online!

Every other letter:

+53@6:2/1+551@6:5+52@66:3/1+552@6:5+3/1+4@6:5/1+3@6:5+1/1+54@6:3/1+552@6:5+1/1+552@6:5+52@6:1/1+551@6:5+1/1+3@6

Try it online!

\$\endgroup\$
8
\$\begingroup\$

Befunge-93, 43 41 bytes

Coming back to this a few years later, I found a way to avoid running those unsupported instructions, meaning this can even be run on implementations that treat those differently.

"!!ddllrrooWW  ,,oolllleeHH"""> :$# ,#__@

Try it online!

Second version

"!dlroW ,olleH">:#,_@

is the shortest possible "Hello World!". This therefore is the shortest possible answer to this question for Befunge-93.

Try It Online

\$\endgroup\$
1
  • 1
    \$\begingroup\$ That's brilliant! Much better than my Befunge answer. Can't believe you haven't got any votes for this. \$\endgroup\$ Commented Dec 20, 2017 at 0:06
8
\$\begingroup\$

05AB1E, 29 bytes

”™ ,ï‚‚ï ! ”# ¦2 ä ø¨øJð ý

Try it online!

Explanation

”™ ,ï‚‚ï ! ”                # push the string "Weekly Hello , Changed World ! "
               #               # split on spaces
                               # RESULT: ['Weekly','Hello',',','Changed','World','!','']
                ¦              # remove the first element (Weekly)
                 2ä            # split in 2 parts
                               # RESULT: [['Hello', ',', 'Changed'], ['World', '!', '']]
                   ø           # zip
                               # RESULT: [['Hello', 'World'], [',', '!'], ['Changed', '']]
                    ¨          # remove the last element
                     ø         # zip
                               # RESULT: [['Hello', ','], ['World', '!']]
                      J        # join each inner list
                       ðý      # join on space

After removing every other character we are left with the code

”Ÿ™,‚ï!” 2äøøðý

Try it online!

Explanation

”Ÿ™,‚ï!”       # push the string "Hello, World!"
        2ä     # split in 2 parts
               # RESULT: ['Hello, ', 'World!']
          ø    # zip, as the string has an odd length the space is lost
               # RESULT: ['HW', 'eo', 'lr', 'll', 'od', ',!']
           ø   # zip again
               # RESULT: ['Hello,', 'World!']
            ðý # join on space
\$\endgroup\$
7
\$\begingroup\$

Octave, 49 45 bytes

Saved 4 bytes since Octave doesn't require brackets to do indexing.

'HHeelllloo,,  WWoorrlldd!! ' (1:2 : 3 ^ 3)''

Try it online!

And the reduced one:

'Hello, World!'(:    )'

Try it online!

Explanation:

The initial code has the letters in the string duplicated, so that we're left with Hello, World! when every second is removed. Some spaces are added to ensure the brackets and apostrophes are kept.

The indexing is really 1:2:end. There are 27 characters, and we can't use end or 27 since we must remove a character, so we go with 3 ^ 3 instead. When we remove every third character, the indexing becomes (:) (and some additional spaces).

(:) means "flatten and turn into a vertical vector". So, we need to transpose it, using '. We don't need to transpose the string in the original code, but double transposing works, so the first string is transposed twice using '', and the second is transposed just once.

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

Mathematica, 62 bytes

P0r0i0n0t0@0"0H0e0l0l0o0,0 0W0o0r0l0d0!0"Print@"Hello, World!"

It returns "0H0e0l0l0o0,0 0W0o0r0l0d0!0" Null P0r0i0n0t0[0], and prints Hello, World! as a side effect. When run as a program (not in the REPL), the return value will not be printed.

After removing every other character:

Print@"Hello, World!"rn@Hlo ol!

It returns Null ol! rn[Hlo], and prints Hello, World!.

\$\endgroup\$
6
\$\begingroup\$

CJam, 32 bytes

"HHeelllloo,,  WWoorrlldd!! "2 %

Try it online!

Taking every other character gives:

"Hello, World!" 

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Note the trailing space on the alternated version. \$\endgroup\$ Commented Jun 26, 2017 at 20:59
6
\$\begingroup\$

Help, WarDoq!, 2 bytes

Hi

Try it online!

H prints Hello, World!, i is a no-op.

Help, WarDoq! can add two numbers and test for primes, so it is considered as a valid programming language per this meta post.

\$\endgroup\$
3
  • \$\begingroup\$ why was this downvoted? \$\endgroup\$
    – Uriel
    Commented Jul 1, 2017 at 22:33
  • \$\begingroup\$ NOP and massive spaces are against the spirit. \$\endgroup\$
    – RShields
    Commented Jul 3, 2017 at 0:09
  • 2
    \$\begingroup\$ +1 because of the novelty on how the resulting source code re-emphasizes the message that gets output. \$\endgroup\$
    – TOOGAM
    Commented Jul 4, 2017 at 9:53
6
\$\begingroup\$

///, 25 bytes

H\e\l\l\o\,\ \W\o\r\l\d\!

Try it online!

With every other character removed:

Hello, World!
\$\endgroup\$
6
\$\begingroup\$

><>, 47 bytes

Original:

| v~" H e l l o ,   W o r l d ! "

~o<< ;!!!? l

With every second character removed:

|v"Hello, World!"
o<;!?l

Try them online: original, modified

The original program pushes the characters of "Hello, World!" to the stack (in reverse order) interspersed with spaces, then alternately prints a character and deletes one until the length of the stack is zero. The second program does the same, except the deletion instructions ~ are gone.

If you don't mind halting with an error, we can take a leaf out of Martin Ender's Cardinal book: the modified code is

\"!dlroW ,olleH"!#o#

and the original is the same but with newlines inserted between all the characters, for 39 bytes. Try them online: original, modified.

\$\endgroup\$
6
\$\begingroup\$

APL (Dyalog), 35 34 bytes

-1 thanks to Martin Ender.

'0H0e0l0l0o0,0 0W0o0r0l0d0!0'~ ⍕ 0

Try it online!

'0H0e0l0l0o0,0 0W0o0r0l0d0!0' the message with zeros as removable filler characters

~ except

 formatted (stringified)

0 number zero

Leaving just the odd characters, this becomes 'Hello, World!' .

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

,,,, 34 bytes

 2"Hteoltlaol,l yWhourmladn!! "⟛

On removing the even numbered characters...

 "Hello, World!"

Explanation

With all the characters:

 2"..."⟛

               no-op
 2             push 2 to the stack
  "..."        push "Hteoltlaol,l yWhourmladn!! " to the stack
       ⟛      pop 2 and the string and push every 2nd character of the string
               implicit output

Without the even numbered characters:

 "..."

               no-op
 "..."         push "Hello, World!" to the stack
               implicit output
\$\endgroup\$
3
  • 5
    \$\begingroup\$ This implies you don't need to say this is non-competing. \$\endgroup\$ Commented Jun 26, 2017 at 20:54
  • 2
    \$\begingroup\$ But you're supposed to keep all of the even-indexed characters... (0-indexed)... \$\endgroup\$
    – hyperneutrino
    Commented Jun 26, 2017 at 21:06
  • \$\begingroup\$ Whoops, fixed. Just add another character lol. \$\endgroup\$ Commented Jun 26, 2017 at 21:15
6
\$\begingroup\$

JavaScript, 138 bytes

A lot of people used comments and I found it too easy so here's one entry without comments:

c_n_o_e_l_g ="c o n s o l e . l o g"; console.log ( "_H_e_l_l_o_,_ _W_o_r_l_d_!".replaceAll( "_","") ) ;[ ' s l i c e ' ]+( 0 , - 9 )+ ")"

Taking every other character out:

cnoelg=console.log;cnoelg("Hello, World!.elcAl _,"  ['slice'](0,-9) )

Important

This code uses String.prototype.replaceAll(), which is a fairly recent feature, and thus wont work in older browsers/NodeJS versions (NodeJS v15.0.0 and above is required, for example).

Explanation

  1. First it create an alias of console.log named c_n_o_e_l_g which returns the same as console.log when every other character is removed.
  2. Then console.log is called (being replaced with cnoelg when converted).
  3. Inside console.log there's "_H_e_l_l_o_,_ _W_o_r_l_d_!" in which every underscore (_) is removed, but not in the converted version (they will be removed anyway because in even position); because of the clever placement of the last double quote ("), the string will look like "Hello, World!.elcAl _,".
  4. Since "Hello, World!.elcAl _," needs to be cleaned up, a slice() is applied with the brackets notations ([]), removing the last 9 characters (".elcAl _,").
  5. But we don't want any modification to happen to the not converted version, so a ) closes the console.log being removed when converted alongside a ; (since in even position). Then it will apply correctly to the converted version but nothing will happen to the not converted one, since it's a value not assigned to anything.
  6. This consist of [ ' s l i c e ' ], ( 0 , - 9 ) and ")", concatenated with a + sign (removed during conversion), so that the script stays valid. The last ")" is there to close the console.log in the converted version.
\$\endgroup\$
5
\$\begingroup\$

Brainfuck, 155 bytes

- - < - < < + [ + [ < + > - - - > - > - > - < < < ] > ] < < - - . < + + + + + + . < < - . . < < . < + . > > . > > . < < < . + + + . > > . > > - . < < < + .

Try it online!

Every second character removed:

--<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.
\$\endgroup\$
1
  • \$\begingroup\$ Well, it's valid, I guess... \$\endgroup\$
    – CreaZyp154
    Commented Nov 18, 2021 at 12:16
5
\$\begingroup\$

T-SQL, 75 bytes

---
PRINT 'Hello, World!'
/*
-P-R-I-N-T-'-H-e-l-l-o-,- -W-o-r-l-d-!-'
---*/

Single- and multi-line comment abuse, inspired by CalculatorFeline's LUA version.

After removal of all even-numbered characters, some of which are line breaks:

--PIT'el,Wrd'/
PRINT'Hello, World!'--/
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.