# 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? – vroomfondel Jun 26 '17 at 20:20
• Amazing first post! – Adám Jun 26 '17 at 22:49
• Seeing all the answers with "HHeelllloo" reminded me of speaking Whale. – Brian Minton Jun 27 '17 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!" – Martin Ender Jun 27 '17 at 7:15
• "No solutions with fewer than 2 characters." Amazing. – Rob Grant Jun 28 '17 at 9:10

# Brainfuck, 155 bytes

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


Try it online!

Every second character removed:

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


# 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

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!");}


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

# 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


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

# 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 # PHP, 63 bytes # echo"Hello, World!"; #eecchhoo""HHeelllloo,, WWoorrlldd!!"";  Try it online! # PHP, 32 bytes #eh"el,Wrd" echo"Hello, World!";  Try it online! # 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, 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 '17 at 9:58 • Just remove the first space. Then everything works out and you can save a byte in the process :) – Datboi Jun 27 '17 at 10:05 • My bad, fixing... – Oliver Ni Jun 27 '17 at 15:47 # 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.

# Stax, 33 bytes

"zHzezlzlzoz,z zWzozrzlzdz!z"'z -


Run and debug it

Every other character, 17 bytes

"Hello, World!"z-


Run and debug it

In the first version, 'z - remove all zs from the string. In the second version, z by itself is empty set, and z- is noop.

# Lost, 113 bytes

v<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>.%?"Hello, worldvU"-+@
v>v%v?v"vHvevlvlvov,v
wvovrvlvdvvvUv"v-v+v@


Try it online!

# With removal, 57 bytes

v<<<<<<<<<<<<<<<<<<<<<
.?Hlo olv"+
>%?"Hello, worldvU"-+@


Try it online!

# Pyth, 31 bytes

%y1t"pHEeGlGlhoz,e QwjolrDlBdJ!


eh

# Forth, 61 bytes

This uses the fact that \ makes the rest of the line a comment.

 \  . (   H e l l o ,   W o r l d ! )   \
.( Hello, World! )


Full program

Remove every other byte to get:

  .( Hello, World!) \ (Hlo ol!)


Every other

# 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 – Eric Duminil Jun 28 '17 at 14:42
• 61 bytes (Includes Eric Duminil's test suite) – Value Ink Jun 30 '17 at 2:51

# Japt, 32 28 bytes

Wrote this up and then noticed Oliver beat me to it with the same method in 05AB1E.

Note: The empty line after the comma contains a space character and the empty line after the "W" contains an unprintable.


H
e
¥
o
,

W

l
d
!
 rR


Test it

With every second character removed, it becomes (with the unprintable still present between the "W" and the "l"):

He¥o, Wld!r


Test it

# Swift, 77 bytes

/**/print("Hello, World!")//  * / p r i n t ( " H e l l o ,   W o r l d ! " )


Every other character:

/*pit"el,Wrd"/ */print("Hello, World!")
`