15
\$\begingroup\$

In your language of choice, write a program that outputs exactly Hello world!. Each character in your program must be repeated n times - you choose n.

For example, you might choose 2 for n. This means that every character used in your source code must be repeated that many times, or 0.

If I were to choose 3 for n, this program would be valid:

ab(b(b(aa)));;;

Rules:

  • You cannot use any external resources
  • No user input can be provided
  • You must output exactly Hello world!, no more, no less. Newlines are the exception, they are optional.
  • n must be >= 2, to keep things interesting
  • It's highly discouraged to use comments to accomplish your goal.

Popularity contest, ending in 14 days. Highest score answer at the end wins!

\$\endgroup\$

closed as too broad by Dennis Sep 30 '16 at 17:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Let's steal every answers from this topic: codegolf.stackexchange.com/questions/18925/… with n=1 \$\endgroup\$ – Fabinout Jan 21 '14 at 17:33
  • \$\begingroup\$ Oops, let's say that n>=2, @Fabinout \$\endgroup\$ – Undo Jan 21 '14 at 17:33
  • 1
    \$\begingroup\$ here's a JSFiddle I threw together for testing if anyone needs it \$\endgroup\$ – Doorknob Jan 21 '14 at 22:22
  • 2
    \$\begingroup\$ I'd love to see a HQ9+ solution for this. \$\endgroup\$ – Nzall Jan 22 '14 at 8:38
  • 1
    \$\begingroup\$ @Nate HQ9+ outputs a comma (as noted in a deleted answer). ;-) \$\endgroup\$ – Doorknob Jan 22 '14 at 13:31

26 Answers 26

25
\$\begingroup\$

Brainfuck

n=57. 45 newlines removed thanks to ratchet freak

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

A more readable version:

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

The last line (on the readable version) is for filling up the character count. They are not comments. The [] are while(0)s, and the ><s are in essence no-ops

\$\endgroup\$
  • \$\begingroup\$ couldn't you put the . inside one of the [] and not output the newlines \$\endgroup\$ – ratchet freak Jan 21 '14 at 20:21
  • \$\begingroup\$ @ratchet freak Good point. Thanks. \$\endgroup\$ – ace_HongKongIndependence Jan 21 '14 at 21:14
  • \$\begingroup\$ I think ratchet was suggesting moving the [ in the first [] to before the dots, so that it wouldn't output even NULLs. \$\endgroup\$ – Ilmari Karonen Jan 22 '14 at 11:34
  • \$\begingroup\$ @Ilmari Karonen Oh right, I see. Thanks. \$\endgroup\$ – ace_HongKongIndependence Jan 22 '14 at 13:24
12
\$\begingroup\$

JavaScript

alert(("aaaeerrttt((,,,HHHoo   wwwddd!!!))","Hello world!"))

This seemed a little too easy.

\$\endgroup\$
12
\$\begingroup\$

Python 3, n = 3, no comments

dwwppHottedHen =print((("H[e]l1l1o\\ !w!orrilidn!\""[::2][:12])))== 2

Not too hard for a Pythonist to understand. ;) (Hint: try "abcdefghijk"[::2] and see what it results in)

By the way, a HottedHen is a warmed up chicken, if you were wondering. (The dwwpp before it stands for drinking water with purple pancakes, because that's what the hens were doing when I was writing it. Everyone knows that purple pancakes go well with water. Obviously.)

\$\endgroup\$
11
\$\begingroup\$

C, 54

main(Hadmeinwurst015p){{!puts("Hello\40wor\154d!");;}}
\$\endgroup\$
  • 1
    \$\begingroup\$ You have a v that doesn't match \$\endgroup\$ – Eduard Florinescu Jan 21 '14 at 22:15
  • \$\begingroup\$ @Eduard hm, you're right, it must've slipped in there accidentally because it doesn't seem to have been included in the character count... fixed. \$\endgroup\$ – FireFly Jan 21 '14 at 22:28
5
\$\begingroup\$

Golfscript - 32

New version with 2 of each used character - 32 - Test online

;"Hello wor\x6cd!" '\Hewrx6cd!';

Old version - 39 - Test online

;;'Hello world!'  "'HHeewworrdd!!\\\"";

EDIT: Updated since rules was updated saying it was discouraged with the use of comments

\$\endgroup\$
  • \$\begingroup\$ Much better without comments! \$\endgroup\$ – Undo Jan 21 '14 at 17:46
4
\$\begingroup\$

Java - 1221 chars

Each character is repeated (int)'!' number of times.

public class ncharacterHelloworld {
    public static void main(String[] args){
        {;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;
{;{;{;{;{;{;{;{;{;{;{;{
String pppppppppppppppuuuuuuuuuuuuuubbbbbbbbbbbbbbbllllllllllliiiiiiiiiiicccccccccccccaaaaaaaaaaaassssssssssssssnnnnnnnnnnnnnhhhhhhhhhhhhhhhhrrrrrrrrrrrrttttttttttteeeeeeeeeeeeeeHHHHHHHHHHHHHHHooooooooooooowwwwwwwwwwwwwwwdddddddddddddddvvvvvvvvvvvvvvvvmmmmmmmmmmmmmmmSSSSSSSSSSSSSSSgggggggggggggggyyyyyyyyyyyyyyyy="Hello world!",
a=pppppppppppppppuuuuuuuuuuuuuubbbbbbbbbbbbbbbllllllllllliiiiiiiiiiicccccccccccccaaaaaaaaaaaassssssssssssssnnnnnnnnnnnnnhhhhhhhhhhhhhhhhrrrrrrrrrrrrttttttttttteeeeeeeeeeeeeeHHHHHHHHHHHHHHHooooooooooooowwwwwwwwwwwwwwwdddddddddddddddvvvvvvvvvvvvvvvvmmmmmmmmmmmmmmmSSSSSSSSSSSSSSSgggggggggggggggyyyyyyyyyyyyyyyy,
u="\"=============================,,,,,,,,,,,,,,,,,,,,,,...............................",b="\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\\\\\\a",i,l,c,t,H,o,w,m;int[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]ffffffffffffffffffffffffffffffff;
        if(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!!true)))))))))))))))))))))))))))))))
System.out.println(a);
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
    }




}

I got tired of putting all the = and , and the like in the code, so I ended dumping them all in a String; not a comment, a string. Every valid character is used for a variable name.

\$\endgroup\$
3
\$\begingroup\$

Windows Command Script - 33 bytes

3 of everything:

ecHo Hello world!% eHccwwrrdd!!%%
\$\endgroup\$
3
\$\begingroup\$

Windows Command Line - 42 Bytes

n=3

ecHo.Hello world! 2>^>2cceHwwrrdd!.. 2>^^!

Batch - 45 Bytes

@ecHo.Hello world! 2>^>2cceHwwrrdd@@..! 2>^^!


2> redirects stderr to a file called >22cceHwwrrdd - > is an invalid character for a file name - redirect the output of that error to a file called ^!.

Realized that I completely ignored ! and >. Dang.

\$\endgroup\$
  • \$\begingroup\$ I spy 4 spaces :( \$\endgroup\$ – eithed Jan 22 '14 at 0:18
3
\$\begingroup\$

Ruby - 40 Chars (n=2)

print "Hel\x6co World!"||'pintHe\x6cWd!'
\$\endgroup\$
  • \$\begingroup\$ How many spaces do you have? Is it correct to say that the first two around p are tabs (or something similar)? \$\endgroup\$ – Justin Jan 22 '14 at 4:41
  • \$\begingroup\$ @Quincunx First space was a typo.Now edited \$\endgroup\$ – Siva Jan 22 '14 at 4:45
3
\$\begingroup\$

PHP - 30 bytes, n = 2

Hell<?='=s?<;^2s'^RSHSI2VReIV;

Shortest solution thus far. I may be able to reduce this by 2-4 more bytes.

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

PHP

<?print"H\145llo wor\154d!"; $Hwpintd<>!'$';?>

Shorter version (42 char):

<?print"H\145llo wor\154d!"; 'Hwd<pint?!';

Online page with that source

\$\endgroup\$
  • \$\begingroup\$ I think you can: - not end with ?> (which will eliminate the use of >) - treat Hepwintd<! as string - 'Hepwintd<!' which will take care of $ \$\endgroup\$ – eithed Jan 21 '14 at 19:16
2
\$\begingroup\$

Jelly, 16 bytes (non-competing)

“⁸ƒẹI4»
“⁸ƒẹI4»

(+trailing newline)

Try it online! (n = 2)

NO COMMENTS AT ALL. I assure you. Just Link 1 and the Main Link.

\$\endgroup\$
  • \$\begingroup\$ And yes I know this is not code-golf. \$\endgroup\$ – Erik the Outgolfer Sep 29 '16 at 18:23
  • \$\begingroup\$ Hmm... so this answer paved the road to close for this challenge. Nice. \$\endgroup\$ – Erik the Outgolfer Oct 1 '16 at 12:41
1
\$\begingroup\$

Golfscript, 42

."Hello world!"'\\\'"  HHeeowwrrdd!!'..;;;

Test online

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

Perl (51 bytes)

print'Hello world!'; ppriinnttHHeeowwdd; "'\"\\!!";
\$\endgroup\$
  • \$\begingroup\$ Old post and probably doesn't matter too much, but you can save a few bytes using $' or $" inside a q!! block instead of the `\`s. \$\endgroup\$ – Dom Hastings Sep 30 '16 at 11:53
1
\$\begingroup\$

C, 75 56 54

2 of everything

main(HWacdeimnprstux6) {{!puts("Hel\x6co\ World!");;}}

main( ){puts("Hello Wor\x6cd!\0!;HWacdeimnprstux06{}");}

3 of everything.

main(){puts("Hello World!\000!!;;HHWWaaddeeiimmnnpprrssttuu{}{}\"\()o");}

Puts stops reading after the first null byte (\000), and only outputs everything before it.

\$\endgroup\$
  • \$\begingroup\$ In the first i is kind of lonely! :) \$\endgroup\$ – Eduard Florinescu Jan 21 '14 at 22:20
  • \$\begingroup\$ Your first two have only one i (easy to fix: change the main argument name). Your last only has one space \$\endgroup\$ – Doorknob Jan 21 '14 at 22:20
  • 1
    \$\begingroup\$ @EduardFlorinescu Lol, I posted that exactly at the same time as you :P \$\endgroup\$ – Doorknob Jan 21 '14 at 22:21
  • \$\begingroup\$ Oops, the first was missing. The second had it, just out of place. \$\endgroup\$ – Kevin Jan 21 '14 at 22:26
1
\$\begingroup\$

Python:

With 3 characters each.

print 'Hello world!'#He's aware#paints#Hipos!nddwt!

nddwt is a rhino!

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

JavaScript 40 (n=2)

I took a slightly different approach to @eithedog, using the left over letters to act as a logic trigger, so that it was absolutely essential to use it to activate the alert function.

('Hawtd !')&&alert("He\x6c\x6co world!")

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

Python 2, 38

deinptw=H=5; print"Hel\154o world\41";
\$\endgroup\$
1
\$\begingroup\$

Javascript, 40

alert("Hel\x6Co wor\x6Cd!", !('adtHw,'))

If I'm not mistaken every character appears twice (though I started seeing double, so I'm not sure)

edit: And, if abusing the rules - 36:

alert("Hel\x6Co wor\x6Cd!")( !wdatH)

(abuse = while output is given as a prompt, the console displays the error - don't know how to treat this).

\$\endgroup\$
  • 2
    \$\begingroup\$ r appears 3 times while w only appears once. (in both versions) Just replace the final r with w to fix it \$\endgroup\$ – Doorknob Jan 21 '14 at 22:19
  • \$\begingroup\$ Oh, dyslexia, you cruel mistress... Thanks! \$\endgroup\$ – eithed Jan 22 '14 at 0:07
1
\$\begingroup\$

Bash, 39

echo -e "H\r--w\"!wccdd!\rHello world!"

This displays exactly Hello world!, and is 39 chars if you omit the trailing newline (bash doesn't seem to need it).

If you need a case-sensitive version, it becomes 42 chars:

echo -e "HhhH\r--w\"!wccdd!\rHello world!"
\$\endgroup\$
1
\$\begingroup\$

JavaScript (52 characters)

alert(['He\x6C\x6Co world!'][(!1,0)-0], +-1+"Hadtw")

Each character is used 2 times, and it doesn't use any comments!

Note: I posted this answer here first.

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

Golfscript x4 -- No extra symbols -- Using all possible commands

'HHHeeelWWWrrrd'!!! do do 'Hello world!'

I tried to do one that didn't have any extra symbols beyond what was absolutely necessary (though I could have chosen " instead of ' or ")

As a secondary goal I also wanted to put as few characters as possible into a string as possible, so I used the ! operator as such, and I also squeezed in to do operators.

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

R, 346 characters, n = 12

cat((((((((((intToUtf8(c(40,69,76,76,79,0,55,79,82,76,68,1)+31+1+0+0+0+0+0+0+0+0++0*11111111[1]*22222222222[1]*33333333333[1]*44444444444[1]*5555555555[1]*6666666[1]*7777777[1]*888888888[1]*999999*9[1]*9[1]*9[1])))))))))),"\"\"\"\"\"\"\"\"\"\"\\aaaaaaaaaaaccccccccccfffffffffffiiiiiiiiiiinnnnnnnnnnnoooooooooootttttttttTTTTTTTTTTTUUUUUUUUUUU"[0])

Characters used in this code:

,"()[]*\+0123456789acfinotTU
\$\endgroup\$
1
\$\begingroup\$

Classic ASP (VBScript; 62 characters)

Hel<%REspOnsE.wRite Chr((0<0>-.6&"!")+&H6C+h-dinptO)%>o world!

Uses each character exactly 2 times!


Edit: This code is a bit shorter:

Hel<%= Chr((0<0>we=6&"!")+&H6C+hd)%>o world!

And so is this:

Hel<%= CHr((0<1>wedC=8&"!&")++108)%>o world!
\$\endgroup\$
1
\$\begingroup\$

Befunge 98 - 26 bytes

Since I had to duplicate the r anyway, I figured I may as well make the source text read left-to-right rather than typical gnirts Befunge style. There's nothing particularly notable about this; I'm not sure if having code that simply isn't executed counts as a comment, but the six characters Hel w! are just ignored.

rHel w!@,dk"Hello, world!"
\$\endgroup\$
0
\$\begingroup\$

Turtlèd, n=3, (noncompeting)

N=3, because of "Hello world!" having three ls.

'!' ' HHeeowwrrdd"Hello world!""!

Try it online

Explanation:

'!                                write exclamation mark
  ' '                             write space twice on the same cell as exclamation mark
      HHeeowwrrdd                 balances chars in Hello world!, moves the pointer
                 "Hello world!"   Write Hello world! to grid
                               "! Write the exclamation mark again, on top of the last one
\$\endgroup\$

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