Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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!

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

24 Answers 24

up vote 18 down vote accepted

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

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

JavaScript

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

This seemed a little too easy.

share|improve this answer

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

share|improve this answer
2  
+1 for imagination –  Eduard Florinescu Jan 21 at 22:07

C, 54

main(Hadmeinwurst015p){{!puts("Hello\40wor\154d!");;}}
share|improve this answer
1  
You have a v that doesn't match –  Eduard Florinescu Jan 21 at 22:15
    
@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. –  FireFly Jan 21 at 22:28

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

share|improve this answer
    
Much better without comments! –  Undo Jan 21 at 17:46

Windows Command Script - 33 bytes

3 of everything:

ecHo Hello world!% eHccwwrrdd!!%%
share|improve this answer

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.

share|improve this answer
    
+1 for the great use of case insensitivity... –  WallyWest Jan 21 at 22:56
    
I spy 4 spaces :( –  eithedog Jan 22 at 0:18
    
Whoops. Fixed, thanks. –  unclemeat Jan 22 at 0:26

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.

share|improve this answer

Ruby - 40 Chars (n=2)

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

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.

share|improve this answer

Golfscript, 42

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

Test online

share|improve this answer

PHP

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

Shorter version (42 char):

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

Online page with that source

share|improve this answer
    
I think you can: - not end with ?> (which will eliminate the use of >) - treat Hepwintd<! as string - 'Hepwintd<!' which will take care of $ –  eithedog Jan 21 at 19:16

Perl (51 bytes)

print'Hello world!'; ppriinnttHHeeowwdd; "'\"\\!!";
share|improve this answer

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.

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

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

share|improve this answer

Python 2, 38

deinptw=H=5; print"Hel\154o world\41";
share|improve this answer

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

share|improve this answer
2  
r appears 3 times while w only appears once. (in both versions) Just replace the final r with w to fix it –  Doorknob 冰 Jan 21 at 22:19
    
Oh, dyslexia, you cruel mistress... Thanks! –  eithedog Jan 22 at 0:07

Python 2.X:

print 'Hello world!'
"printHelloworld!"
share|improve this answer
    
Clever, but your quotes and spaces are more than n=2. –  John Chadwick Jan 22 at 12:33
    
@JohnChadwick fixed, see edited answer –  Dhara Jan 22 at 12:38
2  
There are 6 ls. –  Sven Hohenstein Jan 29 at 18:56

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!"
share|improve this answer

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
share|improve this answer

Python:

With 3 characters each.

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

nddwt is a rhino!

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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!
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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