# Hello, World! (Every other character)

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

abc
def


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

acdf


No solutions with fewer than 2 characters.

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

My naive solution

# C/C++, 111 105 byes 97 bytes

(6 bytes saved using "puts", inspired by Hawkings)

///
f(){puts("Hello, World!");}
#define x\
_f_(_)_{_p_u_t_s_(_"_H_e_l_l_o_,_ _W_o_r_l_d_!_"_)_;_}


After takeaway

//f)pt(Hlo ol!)}#eiex
f(){puts("Hello, World!");}


# Befunge-98, 39 bytes

"" '!'d'l'r'o'W' ','o'l'l'e'H ""c k , @


Try it online!

Every second character removed:

" !dlroW ,olleH"ck,@


Try it online!

# Jelly, 32 bytes

 2“HHeelllloo,,  WWoorrlldd!! ”m


Try it online!

-2 bytes thanks to @totallyhuman's answer

Now mine is a dupe >.<

Go upvote that one too :D

# dc, 112

 6   C * P
A d * 1 + d P
7 + d P
d P
3 + d P
B   4 * d P
C - P
F   6 * 3 - P
d P
3 + d P
6 - d P
8 - P
B   3 * P


All odd-indexed characters are whitespace that don't affect the output of the program. Character values are built arithmetically from single digits

# Java 8, 245243241239238 237 bytes (full program)

/**/interface M{static void main(String[]a){System.out.print("Hello, World!");}}//**/ iinntteerrffaaccee  MM{{ssttaattiicc  vvooiidd  mmaaiinn((SSttrriinngg[[]]aa)){{SSyysstteemm..oouutt..pprriinntt((""HHeelllloo,,  WWoorrlldd!!""));;}}}


Try it online.

After removing every other character:

/*itraeMsai odmi(tig])Sse.u.rn(Hlo ol!)}/*/interface M{static void main(String[]a){System.out.print("Hello, World!");}}


Try it online.

-2 bytes (243 → 241) thanks to @OlivierGrégoire.
-2 bytes (241 → 239) by creating a port of @SuperStormer's JavaScript answer.

# Java 8, 63 bytes (lambda function)

/**/v->"Hello, World!"//**/vv-->>""HHeelllloo,,  WWoorrlldd!!""


Try it online.

After removing every other character:

/*v>Hlo ol!/*/v->"Hello, World!"


Try it online.

Explanation:

Utilizes //abc single-line comments and /*abc*/ multi-line comments.
See the Java-highlighting of the two programs/functions to see how these type of comments are used.

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

# Standard ML (MLton), 75 bytes

(*p r i n t " H e l l o ,   w o r l d ! " ( *)print"Hello, world!"(*  * )*)


Try it online!

After removing every other character, we have:

(print"Hello, world!"(*pitHlo ol!( *))


Try it online!

Just exploits the fact that comments are a digraph.

# Pip, 33 bytes

"0H0e0l0l0o0,0 0W0o0r0l0d0!0"RM 0


Removes the 0s from the string, leaving just Hello, World!. Try it online!

The every-other-character version:

"Hello, World!"M0


Uses the map operator to replace each character in 0 with the string "Hello, World!". Try it online!

# TeX, 54 bytes

Full version:

 %H e l l o ,   W o r l d ! \ e n d%
Hello, World!\end


Every other character:

 Hello, World!\end
el,Wrd\n


A bit boring, but for completeness.

## Alice, 37 bytes

"_!_d_l_r_o_W_ _,_o_l_l_e_H_"_d_&_o_@


Try it online!

Removing every other character gives:

"!dlroW ,olleH"d&o@


Try it online!

The way this works is that Alice's string mode doesn't push all cell values directly to the stack. Some characters have a special meaning. In particular, _ is a wall which retains it's control flow meaning even when in string mode. But a horizontal wall is a no-op when the IP moves horizontally, so none of those _ do anything. Hence, they can be safely removed.

# Self-modifying Brainfuck, 39 bytes

< - [ . <<- ] " e m s p X ! - p m m f I


Try it online!

### Explanation

For anyone that is not familir with self-modifying brainfuck: The program itself gets put into registers directly left to where you start out from. This allows for some cool stuff you can't do with regular brainfuck.

This program will move back two registers (one with every second char removed) increment it and output in until the loop stops. The loop will stop once you increment the char that ends the loop itself thus making brainfuck ignore it.

Version without every second character:

 <-[.<-]"emspX!-pmmfI


# PHP, 63 bytes

#
echo"Hello, World!";
#eecchhoo""HHeelllloo,,  WWoorrlldd!!"";


Try it online!

# PHP, 32 bytes

#eh"el,Wrd"
echo"Hello, World!";


Try it online!

# Japt, 25 23 bytes

Saved 2 bytes thanks to @Shaggy

\H\e\¥\o\,\ \W\Ž\l\d\!


Try it online!

This seems to be the optimal compressed string that would output Hello, World! while ignoring every other \.

## JavaScript (ES6), 65 bytes

Latecomer to the game...

01?alertHello, World! : a_l_e_r_t  H e l l o ,   W o r l d ! 


Becomes:

0?lrel,Wrd:alertHello, World!


Obviously, neither the a_l_e_r_t function nor the lr function does exist. That's OK, because their respective code paths are never executed.

### Demo

let code0 = "01?alertHello, World! : a_l_e_r_t  H e l l o ,   W o r l d ! ";
let code1 = code0.replace(/../g, s => s[0]);

console.log(code0);
eval(code0);
console.log(code1);
eval(code1);

# Ruby, 58 bytes

$/>%< <> > ;puts a= %w( H e l l o ,\ W o r l d ! )* "#{}"  Which becomes: $><<  pt =%(Hello, World!) #}


I borrowed the puts/assignment trick from @G B's solution

Explanation:

The first version compares the ruby global $/ which evaluates to \n to the string " <> " and does nothing with it. Then it creates an array of all the characters in "Hello, World!" and joins them by multiplying by empty string The second pushes the return value of assignment of the string "Hello, World!" (which happens to be "Hello, World!" directly to $> which is the global for standard out.

Try it online!

# Bash, 36 bytes

e\c\h\o  "H"e"l"l"o"," "W"o"r"l"d"!"


With every other character removed:

echo Hello, World!


Invalid escape sequences will be ignored, so \c\h\o makes no difference from cho.

# Rust, 85 bytes

| | /**/print!("Hello, World!")//___*//_p_r_i_n_t_!_(_"_H_e_l_l_o_,_ _W_o_r_l_d_!_"_)


Try it online

Every other character:

||/*pit(Hlo ol!)/_*/print!("Hello, World!")


Try it online

### Full program, 113 bytes

/**/fn main(){print!("Hello, World!")}//__*//_f_n_ _m_a_i_n_(_)_{_p_r_i_n_t_!_(_"_H_e_l_l_o_,_ _W_o_r_l_d_!_"_)_}


Try it online

Every other character:

/*f an)pit(Hlo ol!)/_*/fn main(){print!("Hello, World!")}


Try it online

# C (MSVC), 60 bytes

As Stack Exchange doesn't like me posting null bytes, here is an xxd -g1:

00000000: 6d 00 61 00 69 00 6e 00 28 00 29 00 7b 00 70 00  m.a.i.n.(.).{.p.
00000010: 75 00 74 00 73 00 28 00 22 00 48 00 65 00 6c 00  u.t.s.(.".H.e.l.
00000020: 6c 00 6f 00 2c 00 20 00 57 00 6f 00 72 00 6c 00  l.o.,. .W.o.r.l.
00000030: 64 00 21 00 22 00 29 00 3b 00 7d 00              d.!.".).;.}.


For an infinitely less readable textual version, with 0 representing a raw 0x00 byte:

m0a0i0n0(0)0{0p0u0t0s0(0"0H0e0l0l0o0,0 0W0o0r0l0d0!0"0)0;0}0


### Explanation

I'll see your small brain comment abuse and raise you one cosmic brain text encoding abuse. 😏

Unlike GCC and Clang, MSVC supports files encoded in UTF-16.

That is what we abuse. MSVC will """incorrectly""" auto-detect this file as-is as UTF-16LE, causing it to """incorrectly""" read it as this, encoded in UTF-16LE:

main(){puts("Hello, World!");}


If we remove every other character (a.k.a. removing every 00 byte), it treats it as UTF-8 (well, technically, the current SBCS/MBCS codepage), and it is compiled as you would probably expect, as the codepoints are now the same as they were in UTF-16LE:

main(){puts("Hello, World!");}


You may say "but this is UTF-16, it should be mi({us"el,Wrd";", but I say that U+0000 is a valid UTF-8 codepoint, and it just looks like UTF-16 by """coincidence""".

# Ruby, 63 bytes

puts a= 'Hello, World!'#; p u t s ' H e l l o ,   W o r l d ! '


Which becomes:

pt ='el,Wrd';puts'Hello, World!'


(Abusing comments like a lot of people do)

Try it online!

• Very cool, I couldn't think about any way to write it in Ruby. Here's another way to Try it online Jun 28, 2017 at 14:42
• 61 bytes (Includes Eric Duminil's test suite) Jun 30, 2017 at 2:51

# Braingolf, 42 40 bytes

#"#H#e#l#l#o#,# #W#o#r#l#d#!#" $_ <$_& @


Try it online!

After removing odd characters:

"Hello, World!"&@


Try it online!

## Explanation

Full program:

#"#H#e#l#l#o#,# #w#o#r#l#d#!#" pushes "Hello, World!" (including quotes)

$adds the silent modifier to the next operator space does nothing _ Pops and prints the last item on the stack, but due to silent mode, does not print < moves the first item on the stack to the end of the stack This means that$_ <$_ will remove both quotes from the stack & adds the greedy modifier to the next operator @ pops and prints the last item on the stack as an ASCII character greedy modifier means it prints the entire stack.  With characters removed: "Hello, World!" Pushes Hello, World! Spaces are no-ops &@ Prints entire stack as ASCII @ is not affected by the silent modifier (apparently)  It feels really cheap using no-ops for this, but it's better than the Java/Python comment solutions imo # Noodel, 25 bytes Hðeðlðlðoð,ð¤ðWðoðrðlðdð!  Try it:) ## How it works Hðeðlðlðoð,ð¤ðWðoðrðlðdð! # The ð character breaks the string into an array and pushes the array ["H", "e", "l", "l", "o", ",", "¤", "W", "o", "r", "l", "d", "!"]. # Implicitly printed to the screen (¤ is the space).  Without every other character gives you : Hello,¤World!  <div id="noodel" code="Hðeðlðlðoð,ð¤ðWðoðrðlðdð" input="" cols="12" rows="2"></div> <script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script> <script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script> # Lua, 85 bytes I decided to try making a function copying Lua answer. It's slightly shorter than the comment abuse submission. paints= p_r_i_n_t---- print("Hello, World!") paints( " H e l l o , W o r l d ! " )  Try it online! Alternated: pit=print--pit"el,Wrd" pit("Hello, World!")  Try it online! Alternator script is in my other answer. ## shell (ksh), 58 bytes  #e c h o H e l l o , W o r l d ! # echo Hello World!  (in interactive bash, you'd need to add '\' before the '!') # JavaScript (ES6), 66 bytes / /;alertHello, World! 'a l e r t  H e l l o , W o r l d ! ' //aetHlo ol! alertHello, World! # Python 2, 63 bytes # print'Hello, World!' #p r i n t ' H e l l o , W o r l d ! '  Try it online! After transformation, this becomes: #pitHlo ol! print'Hello, World!'  # Python 2, 73 bytes print"=#0##Hello, World!"[5:] #portionate ""IHeeelallof,A TWookralade!?"  Try it online! Python 2, unfortunately doesn't have that nifty trick the Python 3 answer used :( So I did the obvious comment trickery. "Try it online" code provides the halved version and execs it to make checking easier. Halved version: pit=0#el,Wrd"5] print "Hello, World!"  # C, 111 101 bytes 10 bytes saved thanks to Jasen Full version: //* main(){puts("Hello, World!");} //**// m a i n ( ) { p u t s ( " H e l l o , W o r l d ! " ) ; }  Every other character /*mi({us"el,Wrd"; /*/main(){puts("Hello, World!");}  # 05AB1E, 32 bytes " H e l l o , W o r l d ! "¶ K  Basically the "s make a string, and the ¶ K removes all newlines. Try it online! Version with even characters removed, 16 bytes. "Hello, World!"  Try it online! • Actually, the even characters are removed, not the odd ones. – Okx Jun 27, 2017 at 9:58 • Just remove the first space. Then everything works out and you can save a byte in the process :) Jun 27, 2017 at 10:05 • My bad, fixing... Jun 27, 2017 at 15:47 # Ly, 38 bytes """!!ddllrrooWW ,,oolllleeHH" [po ]  Try it online! Explanation: """HHeelllloo,, WWoorrlldd!!" [po ] """ # open a string literal, close it, then open one again ... # push "HHeelloo,, WWoorrlldd!!" backwards " # close string literal [ # until the stack is empty po # pop off the stack, then output ] # end loop  Every other character: "!dlroW ,olleH"[o]  Try it online! Explanation: "!dlroW ,olleH"[o] "!dlroW ,olleH" # push "Hello, World!" backwards [o] # output until the stack is empty  # Befunge-93, 51 bytes Inspired by Martin's Cardinal solution, I thought it might be fun to try and do something vertical in Befunge as well. It's a little more complicated in Befunge though. ? " ! d l r o W , o l l e H " : >>:v$
#^,__@@
v >


Try it online!

We start with a ?(random direction) command, which can potentially send the instruction pointer in any direction. Left and right will just wrap around back to the start, and going up will hit the v at the bottom of the program and reflect back to the start as well. So while we may bounce around for a while, we'll eventually be forced down at some point, pushing the "Hello, World!" string (in reverse) onto the stack. Which brings us to this sequence:

>>:v
^,__@


This is just a simple output loop that writes out the string on the stack. The only thing out of the ordinary is the extra _ (branch) when the loop terminates. But because there are only zeros on the stack at that point, the second test will safely continue on to to the right, finishing with the @ (exit) command.

Once we remove every second character, the code looks like this:

?"!dlroW ,olleH":>:$#,_@v>  Try it online! Again we start with a ?(random direction) command, and again most directions will just end up wrapping back to the start. So eventually we're forced to go to the right, pushing "Hello, World!" (in reverse) onto the stack. Which then brings us to this sequence: :>:$#,_@


Again this is just a loop outputting the string on the stack. It's very similar to the classic inline print loop, but we've got an extra : (dup) command, and thus require a \$` (drop) to cancel it out.