Hello world! with limited character repetition

80

9

In a language of your choice, write a program that exactly outputs the characters Hello world! followed by a newline. The code:

  • should not use any character more than twice (alphanumeric, symbol, whitespace...anything)
  • should not use any external resources
  • should not use any user input
  • should not output anything else

An example of a valid python program:

print("He%so world!"%(2*'l'))

An example of an invalid python program (the character 'r' is used three times):

print("Hel"+chr(108)+'o world!')

Winner is whoever has the most votes after 14 days.

EDIT: A winner has been chosen! Thanks all for your work on this question!

Josh

Posted 2014-01-17T15:39:12.417

Reputation: 2 783

3Is it allowed to use a letter more than twice in different case? E.g. "RRrr" – Boann – 2014-01-17T16:18:29.020

2@Boann since I did not specify in the original question, it is allowed (since they are technically different characters). – Josh – 2014-01-17T16:33:51.523

25What about the repeated letter o in the "valid" python example. There also these:- " ' ( ) – Adam Speight – 2014-01-17T16:35:26.180

15@AdamSpeight what do you mean? The letter is only used twice, as per the specs. – Josh – 2014-01-17T16:37:07.267

@josh The first condition need to be rewritten to be more clearer.

should not repeat a character more than twice. Eg alphanumeric, symbol, whitespace...anything – Adam Speight – 2014-01-17T16:40:24.057

5@AdamSpeight ... which is literally the same. – VisioN – 2014-01-17T16:42:00.423

1@VisioN It isn't literally the same. The original makes it more prominent that it reads as no repetition. Eg only one use of a character is permitted (which it is what it's asking). Whereas in my version the condition is much easier to read, as it doesn't break the condition into two halves.

comments doesn't preserve the line breaks which makes it impossible to display an example. – Adam Speight – 2014-01-17T16:53:32.480

@AdamSpeight: Then make an edit if you feel that strongly about it. – Chris Laplante – 2014-01-17T17:29:13.683

1It seems, it con not be done using java? – Prizoff – 2014-01-17T17:57:06.477

1@Prizoff I believe so. – Josh – 2014-01-17T18:15:00.983

4I think you mean a character should not appear more than twice, that is, it should not be repeated more than once. – Michael Kay – 2014-01-17T18:15:23.560

56I guess [tag:brainfuck] is out of the question... – jub0bs – 2014-01-17T18:26:44.370

1No, it's not doable in Java. I've been trying to do it for fun. Impossible to do it with less than two s characters. At best, you have to have a class word and a static word, which is three. – asteri – 2014-01-17T19:40:58.520

Do include <file>s count? I can't do it in C++ unless they don't. – None – 2014-01-17T21:17:02.463

includes do count. – Josh – 2014-01-17T21:23:24.063

1You know that you are dealing with ascii values too much when you see any number (in this case, the vote count of 32) and immediately translate into the appropriate character (Space). I guess Befunge just does this to people. – Justin – 2014-01-18T06:41:09.907

1in your valid example 'l' is used twice! – kBisla – 2014-01-18T17:08:31.793

1@BlueFlame reread the requirements especially the first. – Adam Speight – 2014-01-18T18:35:16.583

@BlueFlame It is ok to use a character more than once. You can use 2 of the same characters. – Dozer789 – 2014-01-18T21:54:56.600

how the first python program be valid if it uses 2 os, 2 (, 2), 2 " (quote), 2' (apostrophe), the spec only says that "should not use any character more than twice (alphanumeric, symbol, whitespace...anything)", not "should not use any character more than twice (alphanumeric) repetitively" – phuclv – 2014-01-19T06:59:22.927

Should this question be protected? I've seen at least 2 answers that weren't answers. – Justin – 2014-01-19T09:51:23.373

In-browser javascript console counter: function t(s){return [].reduce.call(s,function(n,c){n[c]=1+(n[c]|0);return n},{})} - usage t('golfcode'). Escape backslashes as \ to avoid getting literals. – Joel Purra – 2014-01-19T14:26:49.720

VB.net (impossible?) Console.WriteLine() As just to output something uses o x 2 e x 3 ( x 1 ) x 1 l x 1 r x 1 Edit Also consider that the minimal about of required ceremony is Module z Sub Main End Sub End Module Also VB doesn't have C#'s escapes sequences \x108 . – Adam Speight – 2014-01-17T19:19:02.690

impossible in D unfortunately as to output anything you need to import std.stdio; (3*t) – ratchet freak – 2014-01-20T09:08:53.017

The valid python also has two r!! – Mehdi – 2014-01-20T12:52:23.307

@JeffGohlke Note that you can get a bit farther by substituting an s by \u0073. You can only substitute one because then you'll run out of 0s, so you still can't have a working Java program (you also need 3 ts and is). – ARRG – 2014-01-20T17:03:49.680

@Mehdi Read the rules again... – Thomas – 2014-01-21T00:22:22.310

1The rules are ambiguous. Your example print("He%so world!"%(2*'l')) uses 'l' and o twice. It also contains multiple r"'() characters in the source, if that matters. – Barry Staes – 2014-01-21T09:55:52.717

1Right. The rules say "should not use any character more than twice (alphanumeric, symbol, whitespace...anything)", so you can have TWO of each character. – Rob – 2014-01-21T16:10:59.473

@Lưu Vĩnh Phúc — What are you trying to say ? – Nicolas Barbulesco – 2014-05-15T11:15:12.690

1@NicolasBarbulesco misread. I thought it was non repetition, only one character allowed – phuclv – 2014-05-15T11:29:26.157

Answers

61

Ruby (1.9+)

Since this is a popularity contest let's try to not use ANY of the characters from 'Hello world!' while still using other characters only a maximum of two times:

puts("S\107VsbG8gV29ybGQhCg".unpack(?m))

It's 40 chars btw.

Bash

And this one uses unicode magic.

Notes:

  • While the orignal characters appear elsewhere (unlike the ruby example), the printed string contains only non-ascii characters.
  • Two from the three spaces are actually tabs, so there are no utf-8 characters that appear more than 2 times
  • As binary some of the octets do appear more than 2 times, hopefully that's not against the rules. I'm trying to resolve them though.

Code:

echo ' ¡'|iconv -t  asCIi//TRANSLIT

For those who don't have a proper font installed it looks like this:

code as image

Here is the hexdump:

00000000  65 63 68 6f 20 27 f0 9d  93 97 f0 9d 90 9e f0 9d  |echo '..........|
00000010  91 99 f0 9d 92 8d f0 9d  93 b8 e2 80 8a f0 9d 93  |................|
00000020  a6 f0 9d 97 88 f0 9d 96  97 f0 9d 96 91 f0 9d 98  |................|
00000030  a5 c2 a1 27 7c 69 63 6f  6e 76 09 2d 74 09 61 73  |...'|iconv.-t.as|
00000040  43 49 69 2f 2f 54 52 41  4e 53 4c 49 54 0a        |CIi//TRANSLIT.|
0000004e

You have to run it on a machine where the default charset is utf-8. I tried on an OSX10.8 using iTerm2 with the following environment:

bash running in iTerm2

PHP 5.4

This uses zLib: (unfortunately it does uses the characters e and o)

<?=gzuncompress('x▒▒H▒▒▒W(▒/▒IQ▒!qh');

Hexdump:

00000000  3c 3f 3d 67 7a 75 6e 63  6f 6d 70 72 65 73 73 28  |<?=gzuncompress(|
00000010  27 78 9c f3 48 cd c9 c9  57 28 cf 2f ca 49 51 e4  |'x..H...W(./.IQ.|
00000020  02 00 21 71 04 68 27 29  3b                       |..!q.h');|
00000029

+1

Here is the ruby 2.0 code I used to test for duplicates:

d=ARGF.read
p [d.split(//),d.unpack('C*')].map{|x|x.inject(Hash.new(0)){|i,s|i[s]+=1;i}.select{|k,v|v>2}}

SztupY

Posted 2014-01-17T15:39:12.417

Reputation: 3 639

2While I always appreciate Unicode cleverness, your bash attempt doesn't seem to satisfy the question's specification. "write a program that exactly outputs the characters Hello world! followed by a newline" – FireFly – 2014-01-17T21:07:42.470

14@FireFly: it does satisfy it. iconv with the target encoding ascii//translit will transliterate the unicode characters to basic ascii. And of course echo will add the newline, so this one fits the spec (if we don't consider the similarity of the octets) – SztupY – 2014-01-17T21:10:29.400

5On my system I get Hello World? instead of Hello World! – marinus – 2014-01-17T21:20:15.637

1@SztupY oh, you're right, my bad. Very clever, I like it! – FireFly – 2014-01-17T21:21:15.113

@marinus this unfortunately depends on the iconv version used. I'll clarify the environment and put up a screenshot. – SztupY – 2014-01-17T21:22:44.093

1How many bonus points would you get if your duplicate-checker also conformed to the repeating spec? :-) – corsiKa – 2014-01-17T22:10:08.397

@corsiKa: I've been thinking about this for 15 minutes, but unfortunately I need at least 4 .-s (and also need to decrease c,h and r from 3): ARGF.chars.sort.chunk(&:ord).each{|y|p y} – SztupY – 2014-01-17T22:28:08.107

@SztupY I'm not a ruby guy, but what if instead of sorting and chunking, you just counted and spit out the counts? That might cut down on the number of .'s, perhaps replacing them with a () pair if you use a closure? But again, I'm not a ruby guy. – corsiKa – 2014-01-17T22:36:02.503

Your first hexdump has the character 9d ten times. – Mr Lister – 2014-01-18T07:21:09.137

1@MrLister '\x9D` is an octet that is part of a single Unicode character. The question did specify repetition of characters, not bytes, so I'd consider this legal. Anyway, he could encode it in UTF-32, in which case going by (32-bit) characters would make it satisfy the rules. – FireFly – 2014-01-18T10:24:08.170

1Congrats on the win, @SztupY! – Josh – 2014-01-31T12:45:57.620

The Bash solution has pretty Unicode  ! :-) However, it does not give the exact string wanted by the question. One can correct this with a ``. – Nicolas Barbulesco – 2014-05-15T12:53:22.153

1@NicolasBarbulesco: oh, you are thi first one to discover that I have used an uppercase W :) – SztupY – 2014-05-15T14:04:02.687

55

You have to use more expressive languages.

Chinese,  6  4   3 chars

喂世!

Running google translate on this produces Hello world!

(thanks @sreservoir and @Quincunx for the update)

Tomas

Posted 2014-01-17T15:39:12.417

Reputation: 2 333

1Haha, 喂世! is giving me "Feed the world!" as the first option. – Timtech – 2017-09-22T15:41:20.780

33+1 for rule bending... "In a language of your choice..." – WallyWest – 2014-01-19T22:54:56.290

4Love it. But how exactly is that a program? – Pierre Arlaud – 2014-01-20T08:42:30.183

3Actually you can look at it as a program in a google translate language - for Chinese as its sub-language :) – Tomas – 2014-01-20T08:44:47.707

2

+1. Nice idea. 世界 = Shì jiè = World. 你好 = nǐ hǎo = Hello. "World, Hello!" translates to "Hello World!". It can be golfed down some more: 你好世!

– Justin – 2014-01-20T21:56:59.793

@Tomas Native speaker? Whom are you talking about? I'm no native speaker; the only part of your answer I understood was 你好 (and the fact that "World, Hello!" means "Hello World!"). I used google translate to figure out the other part. My "improvement" came from fiddling around on google translate. – Justin – 2014-01-20T22:07:47.380

@Quincunx OK, sorry! I supposed no one else would understand Chinese. You are a real hacker. :) I will delete the irrelevant comment. – Tomas – 2014-01-20T22:09:40.113

2can be golfed down further to 喂世! at the expense of ... well, nothing more is really being expended. – muhmuhten – 2014-01-20T23:40:50.923

@sreservoir wow, thanks! Seems to be more exciting than debugging a classical programming language!! :-) – Tomas – 2014-01-21T00:24:48.450

45

HQ9+, 1 char

H

keeping it simple :)

le_vine

Posted 2014-01-17T15:39:12.417

Reputation: 701

7HQ9+ outputs a comma though ;) – Josh – 2014-01-17T15:48:12.423

1oh sh.. you're right! – le_vine – 2014-01-17T15:51:28.270

8I'd still keep your answer out...it is a popularity contest after all, rules are for the wind! – Josh – 2014-01-17T15:53:42.523

3For any challenge like this, HQ9+ should be outlawed just because it's so obvious to begin with. – Iszi – 2014-01-17T15:57:45.570

26@Josh This is one of the rare events where I miss the downvote button on comments. If we throw away rules there is nothing left to justify the contest at all. – Howard – 2014-01-17T16:24:49.313

5@Howard I feel dirty. I upvoted yours and Josh's comment – Cruncher – 2014-01-17T17:03:50.957

This is what I was about to post. Maybe I should post an answer in H9+, HQ9++, CHIQRSX9+, etc.. – The Guy with The Hat – 2014-01-17T18:34:53.667

22All print Hello World questions are actually who can submit a HQ9+ answer faster questions. – totymedli – 2014-01-18T05:49:29.240

What does this output ? – Nicolas Barbulesco – 2014-05-15T12:34:10.810

44

Vim command (18 keystrokes)

iHeEsc3alEscio WorRightd!Enter

Doesn't repeat any keystroke more than twice.

It kinda violates the "user input" rule since it's still the user that needs to input that sequence, but I suppose if you store it as a macro or an nnoremap beforehand it would count, since you're just running it without explicitly doing any input to make it happen.

It also requires nocompatible to be set, which may count as using external resources, so I have provided another variation below:


Vim command (21 keystrokes)

iHeEsc3alEscio WorCtrl+[$ad!Enter

This variation doesn't require nocompatible to be set, although it does work around using Esc three times by using Ctrl+[ in its place.

Joe Z.

Posted 2014-01-17T15:39:12.417

Reputation: 30 589

That's awesome! – Josh – 2014-01-17T18:10:34.280

you have an 'e' and 3 'E'; 3 'i' – bolov – 2014-01-17T18:49:56.450

16If you're talking about the characters in Right, Esc, and Enter, they're not literally those characters. Vim deals in keystrokes, which I am deeming equivalent to characters for the purposes of this contest (and the "don't repeat more than twice" rule). I only use the i keystroke twice, and the <Right> keystroke once. As for E, I never use it at all - but I do use <Esc> twice and <Enter> once. – Joe Z. – 2014-01-17T19:11:52.137

6Now I'm disappointed that Emacs doesn't have a M-x hello-world command... – RemcoGerlich – 2014-01-17T19:34:43.463

4Even if it did, that's three ls. – Joe Z. – 2014-01-17T19:35:27.313

1You should note that you have to :set nocompatible. – jazzpi – 2014-01-19T14:15:18.557

1Amazing, but myself find using Right not very vim-y. – gefei – 2014-01-19T16:11:58.847

@jazzpi: Wait, really? I didn't even notice. – Joe Z. – 2014-01-19T20:58:54.817

What part requires set nocompatible? I found it in my .vimrc, so I think I didn't even notice it wasn't default settings. – Joe Z. – 2014-01-19T20:59:30.557

@JoeZ.: The set nocompatible makes VIM not act like vi, in that vi didn't actually support movement with the arrow keys but would print A, B, C and D instead of applying the movement. – jazzpi – 2014-01-22T19:15:46.883

I see. If you wanted to do it without nocompatible, you'd have to replace Right with something like <C-[>$a, which increases the keystroke count to 21. – Joe Z. – 2014-01-23T00:24:21.137

44

C, 192 chars

#
#
/*$$@``*/ATION_[]={9.};main(BBCDDEEFFGGHJJKKLLMMPPQQRRSSUUVVWWXXYYZZabbdefgghhjjkkmpqqsstuuvvwxyyzz) {printf("He%clo \
world!%c\
",2^7&!8.&~1|~-1?4|5?0x6C:48:6<3>2>=3<++ATION_[0],'@'^79-5);}

Since this isn't golf, I decided to have some fun and try to use every character exactly twice (while putting as few as possible in a comment, because that's boring). I realise that I didn't do terribly well, since my code contains a ton of boring "dead" code too (not in the literal sense, but in the sense of placeholder characters just used in order to fullfil the requirement). Anyway, this was surprisingly hard (but fun) with the two-character limitation, so unfortunately I couldn't come up with anything more interesting. It did give me an idea for a new problem though...

(Updated per @ugoren's comment.)

FireFly

Posted 2014-01-17T15:39:12.417

Reputation: 7 107

3Creatively impressive. I like it. – Josh – 2014-01-17T22:48:40.427

The slash \\ ending lines three and four make it a line continuation, not newline. And line four is terminated by a EOF, making it legal. – Josh – 2014-01-18T06:02:25.957

1I think you can easily uncomment . by using it for fractions. Also you can declare an array and use []. – ugoren – 2014-01-19T15:18:21.403

@ugoren good call about .; I only thought about using it for struct access. <s>As for array declarations, I'm out of ,s due to the printf call, and I'm also out of ;s, so I'm not sure how I could declare one.</s> Duh, I could replace ATION_... – FireFly – 2014-01-19T15:29:13.580

29

Piet-- No characters whatsoever!

Hello world in Piet

ApproachingDarknessFish

Posted 2014-01-17T15:39:12.417

Reputation: 951

7I would consider the codels as "characters". – Paŭlo Ebermann – 2014-01-17T21:16:49.203

3@PaŭloEbermann What would you consider to be a unique codel? EG different shapes? colors? sizes? some combination thereof? – ApproachingDarknessFish – 2014-01-19T19:19:43.967

1

@ValekHalfHeart the definition of a unique codel is given in the specs of the language: it s a block of codel that could be simplified as a single colored pixel.

– plannapus – 2014-03-07T09:30:47.350

@plannapus In that case I don't this challenge is technically possible in Piet. I may come up with something creative though. – ApproachingDarknessFish – 2014-03-07T17:57:16.250

@ValekHalfHeart oh it wasn t a criticism of this answer: i love it! This challenge was not a codegolf anyway. – plannapus – 2014-03-08T07:44:13.683

26

Perl, 29 characters

This answer includes x-rated clogs!

say"07-8*d<#B+>!"^xRATEDkL0GZ

Perl, 23 characters

Shorter, but no porno shoes. :-( Same basic idea though...

say'0@@lo World!'^"x%,"

Perl, 20 characters

Boring...

say"Hello Wor\x6Cd!"

tobyink

Posted 2014-01-17T15:39:12.417

Reputation: 1 233

7Um....kinky? +1 :) – Josh – 2014-01-18T14:32:40.467

23

Powershell, 20

"He$('l'*2)o world!"

Danko Durbić

Posted 2014-01-17T15:39:12.417

Reputation: 10 241

19

Sclipting, 11 characters

丟낆녬닆묬긅덯댦롤긐뤊

I saw this beautiful HelloWorld program on esolang's Hello World program list.

Justin

Posted 2014-01-17T15:39:12.417

Reputation: 19 757

5Whoa! Congratulations, you are the first person ever to post anything about any of my esolangs outside of esolangs.org :) (or at least the first I found out about) – Timwi – 2014-01-20T12:30:46.067

18

Scala: 34 29 characters

I'm proud of myself for this one:

printf("He%c%co world!\n",108,108)

Had a really hard time overcoming duplicate 'l's, 'r's, quotation marks and brackets. Then I discovered the old Java printf function, which will happily convert numbers to letters when given the %c format specifier.

Update

MrWonderful did a wonderful thing by pointing out that a whole bunch of characters can be saved by using up my second 'l' manually in the string!

printf("Hel%co world!\n",108)

KChaloux

Posted 2014-01-17T15:39:12.417

Reputation: 579

4@KCaloux, Since you are allowed up to 2 'l's, wouldn't printf("Hel%co world\n",108) at 28 be even better? – MrWonderful – 2014-01-17T19:11:06.990

@MrWonderful I think you're absolutely correct! (Also I just realized that I forgot to include the '!') – KChaloux – 2014-01-17T19:17:00.620

From what I understand, this isn't a valid entry, though a good attempt at it. printf contains a r as does world. Same goes for the letter o which is used more than once. This is based on my interpretation of the following statement from the OP "An example of an invalid python program (the character 'r' is used three times): print("Hel"+chr(108)+'o world!')" – javatarz – 2014-01-18T09:58:27.427

@JAnderton I had a ruby program parse out my script to make sure there were no characters included more than twice. Read it again. There are 2 rs, not 3. One in "printf" and one in "world". The reason the python one is invalid is because it includes chr – KChaloux – 2014-01-18T16:36:04.127

16

Python 3 [38 bytes]

exec('import '+chr(95)*2+"h\x65llo__")

I wouldn't consider import __hello__ as an external resource.

VisioN

Posted 2014-01-17T15:39:12.417

Reputation: 4 490

15

Perl: 34 characters

$_="He12o wor3d!
";s{\d}{l}g;print

Sample run:

bash-4.1# perl -e '$_="He12o wor3d!
> ";s{\d}{l}g;print'
Hello world!

(Not a big deal. Posted just to use at least once in my life s/// with those fancy delimiters.)

manatwork

Posted 2014-01-17T15:39:12.417

Reputation: 17 865

15

PHP, 33 chars

I just love how much PHP is forgiving and understanding!

<?=Hel.str_rot13("yb jbe").'ld!';

Before it was deleted (or if it's still there, I'm totally blind), I saw a comment saying "No brainf*ck? :D". Well, it is pretty much impossible to write a solution in BrainF*ck, as you know. But I managed to code this, just for the lulz.

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

If you don't have a BF interpreter, the code above just prints the PHP one :P

Vereos

Posted 2014-01-17T15:39:12.417

Reputation: 4 079

I didn't know even a code like this is valid! Php tag isn't closed and string Hel isn't surrounded by quotes. Also I've never heard about str_rot13 before. – Aycan Yaşıt – 2014-01-17T18:56:57.683

1@AycanYaşıt the closing php tag is not required on EOF, and if you put a string without quotes it assumes it is an undeclared constant with the same content as its name and gives a warning – Einacio – 2014-01-17T19:25:06.193

You have two ls... – Manishearth – 2014-01-17T19:50:59.393

@Manishearth Ooh, you should see the comment thread on the question. – Mr Lister – 2014-01-17T20:04:38.970

I commented regarding Brainfuck keeping in mind that it will be completely impossible not to use same characters more than twice :) – VisioN – 2014-01-17T21:19:34.677

1You can avoid the warning (and save the first .) by putting the Hel before the <?=. – Paŭlo Ebermann – 2014-01-17T21:23:06.047

4@PaŭloEbermann Hel<?=str_rot13("yb jbe")?>ld! – MirroredFate – 2014-01-17T23:47:39.733

@VisioN I know, I wrote that just for the lulz, as I stated before! :) – Vereos – 2014-01-18T00:39:05.420

2@PaŭloEbermann I would say that using that is like cheating, since it's not pure PHP anymore. – Vereos – 2014-01-18T00:43:26.737

13

HTML Fiddle - 21 characters

Hel&#108;o World!<br>

Briguy37

Posted 2014-01-17T15:39:12.417

Reputation: 2 616

Does that include the trailing newline? – Josh – 2014-01-17T18:32:28.853

Doh...missed that requirement! I'll add a <br> in there. – Briguy37 – 2014-01-17T18:36:47.227

I'm not quite sure that the <br> tag actually outputs a \n character. – Kyle Falconer – 2014-01-17T22:48:22.833

7@netinept :It asked for a newline, not a \n so I'd say <br> counts – Chris – 2014-01-17T22:54:26.247

1But the character r is repeated in the solution. Did I misinterpret the requirements? – javatarz – 2014-01-18T09:59:24.277

2"l" and "o" too, but each character can be used twice at most. – xem – 2014-01-18T14:04:46.887

12

Ruby: 27 characters

puts [:Hel,'o wor',"d!"]*?l

Sample run:

bash-4.1# ruby <<ENDOFSCRIPT
> puts [:Hel,'o wor',"d!"]*?l
> ENDOFSCRIPT
Hello world!

Ruby: 25 characters

(Based on Vache's comment.)

puts 'He'+?l*2+"o world!"

Ruby: 23 characters

(Copy of Danko Durbić's Powershell answer.)

puts"He#{?l*2}o world!"

manatwork

Posted 2014-01-17T15:39:12.417

Reputation: 17 865

puts 'He'+'l'*2+'o world!' is one character shorter! – dee-see – 2014-01-17T16:38:13.633

3But has 6 “'”'s… – manatwork – 2014-01-17T16:50:24.043

haha I was so focused on letter characters that I never noticed that. never mind! – dee-see – 2014-01-17T16:53:28.977

@Vache, your comment is actually good. Thank you for it. – manatwork – 2014-01-17T16:57:13.847

1Remove the space after puts and make it 23. -- puts"He#{?l*2}o world!" – Zero Fiber – 2014-01-17T17:52:06.307

Also puts can be replaced by p. So 20 chars. -- p"He#{?l*2}o world!" – Zero Fiber – 2014-01-17T17:56:33.467

1@SampritiPanda, p includes quotes in the output. I prefer to keep strictly with the required output format. But you are right, the space is not needed. Thank you. – manatwork – 2014-01-17T18:17:00.957

12

JavaScript, 66 characters

alert('Hel'+window.atob("\x62G8gd29ybGQhCg=="));//rH+in.\x689yQhC;

Inspired by FireFly, every character used by this code is used exactly twice.

David Cary

Posted 2014-01-17T15:39:12.417

Reputation: 221

I think you are allowed to use some characters just once, and you can drop the comment. – John Dvorak – 2014-01-18T03:19:06.887

2@JanDvorak - well, sure he could have done it that way - but I think this solution is deserving of an upvote for the sheer bloodymindedness of using each and every character exactly twice. :-) – Bob Jarvis - Reinstate Monica – 2014-01-19T01:22:42.140

6+1, but it's easy to use each character exactly twice if you just add gibberish as a comment. – Camilo Martin – 2014-01-19T07:32:57.830

11

C - 43 Characters

main(){printf("Hel%co World!%c",'k'+1,10);}

Output

Hello World!

Character Counts

' ' Count: 1    '!' Count: 1    '"' Count: 2    '%' Count: 2    ''' Count: 2
'(' Count: 2    ')' Count: 2    '+' Count: 1    ',' Count: 2    '0' Count: 1
'1' Count: 2    ';' Count: 1    'H' Count: 1    'W' Count: 1    'a' Count: 1
'c' Count: 2    'd' Count: 1    'e' Count: 1    'f' Count: 1    'i' Count: 2
'k' Count: 1    'l' Count: 2    'm' Count: 1    'n' Count: 2    'o' Count: 2
'p' Count: 1    'r' Count: 2    't' Count: 1    '{' Count: 1    '}' Count: 1

Kirk Backus

Posted 2014-01-17T15:39:12.417

Reputation: 589

Don't you need main etc? – FireFly – 2014-01-17T19:28:41.783

@FireFly I guess so! It did say to write a program. – Kirk Backus – 2014-01-17T19:36:09.093

That's C but not C++. C++ does not have implicit int (and you can't spare another i). – Ben Voigt – 2014-01-17T19:52:43.467

@BenVoigt Okie dokie! – Kirk Backus – 2014-01-17T19:56:51.370

9

JavaScript [37 bytes]

alert(atob("SGVsbG8g")+'wor\x6cd!\n')

Too primitive isn't it?

VisioN

Posted 2014-01-17T15:39:12.417

Reputation: 4 490

5Where’s the newline? – Christopher Creutzig – 2014-01-17T20:26:42.083

@ChristopherCreutzig Sorry, forgot it. Now it is in place. – VisioN – 2014-01-19T00:46:30.267

9

nginx.conf

return  200 "He&#x6clo wo&#x72ld!\n";

In action:

% curl -6 http://localhost/ | lynx -dump -stdin
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0  20958      0 --:--:-- --:--:-- --:--:-- 21000

   Hello world!

%

cnst

Posted 2014-01-17T15:39:12.417

Reputation: 263

There are 4 spaces in this solution... – Josh – 2014-01-17T20:54:39.490

3@Josh, actually, there are 5. But couldn't you consider that two of the first four are tabs, and then the last one is a non-breakable space? :-) – cnst – 2014-01-17T20:58:33.603

That works for me! – Josh – 2014-01-17T21:00:13.927

@Josh, actually, now that we're using HTML, no more need for set. This only has 3 spaces now, any one of which could be a tab! – cnst – 2014-01-17T21:13:19.867

Very nicely done. – Josh – 2014-01-17T21:15:09.603

Uses 3×'r' though – Joel Purra – 2014-01-19T14:00:25.213

@JoelPurra, nice catch, fixed. :-) – cnst – 2014-01-19T20:08:24.657

9

Emacs Command (15 keystrokes)

He<Ctrl-3>l<Left>o wor<End>d!<Enter>

If that vim answers is legal then this must be too :)

Joking aside, macro it can become too :)

More nonsense aside, I can probably squeeze some more, but this seems to be good enough for the time being (since it beats vim).

P.S., please ignore all my nonsense (I (rarely, but)use vim too!).

zw324

Posted 2014-01-17T15:39:12.417

Reputation: 191

2I still think vim > emacs. – Joe Z. – 2014-01-18T05:07:11.723

6

Befunge 98

a"!dlrow ol":'e'Hck,@

Here is a version where every character appears twice.

bka!e:dw"H@!dlrow  ol":'e'Hbk,a,@

Leaves a bunch of junk on the stack.

As a bonus, every single character has something done with it by the IP.

Justin

Posted 2014-01-17T15:39:12.417

Reputation: 19 757

6

Malbolge

(=<`#9]~6ZY32Vw/.R,+Op(L,+k#Gh&}Cdz@aw=;zyKw%ut4Uqp0/mlejihtfrHcbaC2^W\>Z,XW)UTSL53\HGFjW

Timtech

Posted 2014-01-17T15:39:12.417

Reputation: 12 038

Unfortunately, this seems to print Hello, world. instead of Hello world!\n :( Try it online! Impressive, but invalid.

– DLosc – 2018-02-19T08:50:34.490

5

Actually I don't like cheating :P

Python

print("!dlrow os%eH"[::-1]%('l'*2))

Wasi

Posted 2014-01-17T15:39:12.417

Reputation: 1 682

2You should specify that it's for python2. In python3 the you get the reversed string as output and then a TypeError. – Bakuriu – 2014-01-18T07:09:49.600

1For use in Py3K argument of print must by enclosed in parenthesises. print("!dlrow os%eH"[::-1]%('l'*2)) work in both (Python2 and Py3K) versions. – AMK – 2014-01-19T16:24:41.820

4

GolfScript

'He

o world!'n/"l"*

Substitutes two newlines (fortunately the third one, needed for the substitution, is provided by the built-in n), using both types of string literal to avoid quadruplicate copies of a quote mark. Since l is the only character which occurs more than twice in the original string, it's not too hard.

Peter Taylor

Posted 2014-01-17T15:39:12.417

Reputation: 41 901

You forgot the "!". – Howard – 2014-01-17T16:27:05.827

@Howard, missed it. Oops. – Peter Taylor – 2014-01-17T16:31:45.120

The letter o is repeated also – Adam Speight – 2014-01-17T16:34:29.677

1@AdamSpeight: There is only twice the letter o. The rules say that it's not allowed to have a character more than twice. – ProgramFOX – 2014-01-17T16:35:33.527

4

Hmm.

In C, given these rules, we can only have one #define (because of i and n) and at most two function calls OR definitions (( and )).

I presume there's pretty much only one way to do it (though I'm probably wrong):

main(){puts("Hello w\x6fr\154d!");}

Oberon

Posted 2014-01-17T15:39:12.417

Reputation: 2 881

You still need to output the trailing newline. Doing this challenge in C is difficult... – Josh – 2014-01-17T16:55:09.533

1@Josh I just have to use puts() instead of printf(). – Oberon – 2014-01-17T16:59:01.390

2But what's wrong with o in world? – VisioN – 2014-01-17T17:01:55.723

@VisioN In an old draft of the same code (before I realized how hard it actually was to write such a program) I used another 'o' elsewhere. But this isn't [tag:code-golf], so I guess it doesn't have to be fixed. – Oberon – 2014-01-17T17:08:53.477

4In fact, I'm not sure why every answer is displaying a character count. – Oberon – 2014-01-17T17:10:48.890

4

XQuery, 19 chars

"Hello Wor&#x6C;d!"

Michael Kay

Posted 2014-01-17T15:39:12.417

Reputation: 191

4

BASH

printf 'Hel\x6co world!\n'

Cred @manatwork

echo $'Hel\x6c\x6f world!'

Runium

Posted 2014-01-17T15:39:12.417

Reputation: 1 878

The first one has 3 “e”'s and 3 “o”'s. – manatwork – 2014-01-17T18:42:34.400

@manatwork: Gag; thanx ;) – Runium – 2014-01-17T18:43:03.470

In Bash you may skip -e by using the special $'…' syntax: echo $'Hel\x6c\x6f world!'. – manatwork – 2014-01-17T18:48:18.340

4

C - 46 Characters

main(){printf("He%clo wor%cd!\x0d",'l',108);}

Prints out:

Hello world!

Phillip Kinkade

Posted 2014-01-17T15:39:12.417

Reputation: 141

If you're aiming for golf, main(){printf("He%clo world!%c",108,10);} should work, and saves you a few chars. – FireFly – 2014-01-17T19:23:14.593

@FireFly you're right, you'd save me 3 characters. Your suggestion works perfectly, too. – Phillip Kinkade – 2014-01-17T19:43:39.243

4

Fugue

From the esolang wiki:

enter image description here

And you can listen to the source code.

Timtech

Posted 2014-01-17T15:39:12.417

Reputation: 12 038

-1 for using the same note more than 2 times. – Erik the Outgolfer – 2016-10-01T13:51:14.383

11I'd say this is invalid. I can see more than 4 middle c's in the right hand. – Justin – 2014-01-17T21:47:32.873

4Not to mention the string of four consecutive G's in the 9th measure. – Joe Z. – 2014-01-17T21:53:30.890

Did you write this, or only render it? Given that you link to the esolang archive's MIDI. – FireFly – 2014-01-17T22:02:54.897

4

-1 for plagiarism. This is from esolang wiki. You do not cite it. Edit: reverted, now the esolang wiki is cited.

– Justin – 2014-01-17T22:13:31.207

4

PHP

32 Chars

Note how I am not using a character more than twice, since l != L

He<?=strtolower("LLO WOR");?>ld!

Also note that, despite of Stack Overflow deleting it in the representation, there's a line break after the !.

Francisco Presencia

Posted 2014-01-17T15:39:12.417

Reputation: 181

1You are using three spaces, but I guess this can be fixed removing the ones near the PHP tags! :P – Vereos – 2014-01-18T01:05:02.890

1That was fast, although I realized before of reading your comment (from another answer actually) – Francisco Presencia – 2014-01-18T01:07:02.980

Isn't the output "H" supposed to be uppercase? – David Cary – 2014-01-18T02:47:54.803

Completely true, missed that also ): – Francisco Presencia – 2014-01-18T02:49:57.697

3

AWK,34

BEGIN{printf"Hel%co world!\n",108}

Wasi

Posted 2014-01-17T15:39:12.417

Reputation: 1 682

3

GolfScript, 21 characters

'He'[108]+"lo world!"

108 is the ASCII code for l.

First, I push He on the stack. Then, He gets popped and becomes Hel. Then I push lo world! on the stack. Now there are two elements on the stack. Because at the end of a GolfScript program, everything of the stack is outputted, this program outputs:

Hello world!

followed by a newline, because Golfscript always outputs a newline.

ProgramFOX

Posted 2014-01-17T15:39:12.417

Reputation: 8 017

3

nginx.conf

set $i l;
return 202 "Hel${i}o world!\n";

In action:

opti# curl -6v "http://localhost/"
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* connected
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.26.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Server: nginx/1.4.1
< Date: Fri, 17 Jan 2014 18:02:08 GMT
< Content-Type: application/octet-stream
< Content-Length: 13
< Connection: keep-alive
<
Hello world!
* Connection #0 to host localhost left intact
* Closing connection #0

cnst

Posted 2014-01-17T15:39:12.417

Reputation: 263

1Unfortunately your code has three e's and three l's! – Josh – 2014-01-17T18:13:40.260

1One of the duplicate l's can be removed easily. e is harder, unless nginx is case-insensitive – SztupY – 2014-01-17T18:20:35.413

4Don't forget the spaces! – Vereos – 2014-01-17T18:52:09.813

1And 3×'r', as well – Joel Purra – 2014-01-19T14:22:22.917

3

HTML — 17 characters

He&#x6c;lo world!

In action:

%echo -n "He&#x6c;lo world!" | wc
       0       2      17
%echo -n "He&#x6c;lo world!" | lynx -dump -stdin

   Hello world!

%

cnst

Posted 2014-01-17T15:39:12.417

Reputation: 263

3

Clojure (35)

(printf "He%c%co world!\n",108,108)

The whitespace almost got me, but Clojure allows the use of commas to separate parameters.

Bob Jarvis - Reinstate Monica

Posted 2014-01-17T15:39:12.417

Reputation: 544

You could always have used different types of whitespace--space, newline, tab, vertical tab, form feed. I'm not completely sure of Clojure's grammar off the top of my head, but the first tree ones would likely work at least. – FireFly – 2014-01-18T10:37:00.107

1But it was interesting to try out this use of commas in Clojure. I thought I'd read somewhere that they could be used to substitute for whitespace but hadn't messed with it. – Bob Jarvis - Reinstate Monica – 2014-01-18T12:40:44.170

As MrWonderful pointed out for my Scala version, you're only using a single 'l'. You could save a few characters by using your second, for (printf "Hel%co world!\n",108) – KChaloux – 2014-01-18T16:41:45.883

3

Perl, 28 chars

printf"He%so world!\n",'l'x2

Rules tested with:

perl -e '$"="\n";@a=split//,<>;print"@a";' | sort | uniq -c | sort

Tomas

Posted 2014-01-17T15:39:12.417

Reputation: 2 333

3

C (32 characters)

main(){puts("He\x6clo world!");}

mcleod_ideafix

Posted 2014-01-17T15:39:12.417

Reputation: 901

3

Plain TeX - 18 chars

He^^,lo world!\bye

Remark: TeX terminates the paragraph before shipping it, so the "newline" is actually included.

yo'

Posted 2014-01-17T15:39:12.417

Reputation: 563

3

Taking it directly from the instructions on this page:

curl -sL bit.do/gBfx|perl -E'@Q=map{m%OUtPUTS The chARAC.ERS\N*?>([^<]+)%i?$1:()}<>;say$Q[1]'

or, if you wanna be strict with the white-spaces:

PERL

`curl -sL v.gd/92XIMS`=~m%ThE\WChAracTERS.*?>\K[^<]+%i;say$&

or

`curl -sL v.gd/qmwAMh`=~m%outpUtS\WTHE\WChAracTERS.*?>([^<]+)%i;say$1

Advantage: will work for every sentence, but please don't change wording of the question :)

Rules: we can consider this question being an "internal" resource. Without this question, no one would solve it. Should it be me or the program reading it? :)

Backstage story: I almost teared out all my hair trying to debug this! :)

First solution

  • using wget -O- leads to 3x -
  • sed needed too many /
  • so I need curl and perl, but all perl loops like until, while contain 3rd l!
  • I needed to replace the loop, this is quite complicated but
    • it seems $1 only works after positive (=~) not negative (!~) match
    • I couldn't use !(..) - too many parentheses :x
    • neither I could use || (I need a pipe!) or or (perl, curl ...)

Second solution

  • I reread the rules. White-spaces shouldn't be repeated either - oh my!
  • At least could recycle the do{}while idea. Better said, it was forced, the map solution could not be used for using () 2 times, 3rd needed to call open since no more whitespaces are left.
  • Find proper url shortener was a story, using goo.gl, bit.ly, is.gd or ow.ly was obviously impossible for the first solution, as was bit.do and dft.ba for the second. Then, url-shorten the URL until you get something you can use, especially with bit.ly and v.gd. Why on earth they use so much lowercase characters?

The regex could be shortened, but I like the instructions to be as long as possible :-)

These rules are damn crazy :)


PERL v5.10 say feature has to be enabled, e.g. by running PERL -E option

Tomas

Posted 2014-01-17T15:39:12.417

Reputation: 2 333

1For the first one, you have a backslash left, right? You could do two tabs and one escaped newline for the spaces in the shell part. – FireFly – 2014-01-20T09:55:43.163

@FireFly what a neat idea :) I don't now why I limited myself to spaces. I guess because I like one-liners that can just be copy-pasted :) – Tomas – 2014-01-20T09:59:14.780

3

Яussian

Хелло мир!

A mix of transliteration and proper language :) Google translate will turn it into proper "Hello world!"

Indoor

Posted 2014-01-17T15:39:12.417

Reputation: 141

I guess this wouldn't even be accepted in a code-trolling question, lol. Nice interpretation of the In a language of your choice sentence, but here's Programming Puzzles and Code Golf site! – Vereos – 2014-01-20T11:44:49.350

@Vereos thanks :) – Indoor – 2014-01-24T00:53:30.923

3

Keg, 13 bytes

The winner was chosen, but I still want to do it. :) (Astonishingly it is shorter than HTML!)

Hel:o world\!

This is a popularity contest, but the program is very easy to understand despite of the conciseness.

Explanation

Hel          #Push "Hel" onto the stack
   :         #Duplicate the top of the stack (l)
    o world  #Push "o world" onto the stack
           \!#Escape ! and push it onto the stack(since it is an instruction)

user85052

Posted 2014-01-17T15:39:12.417

Reputation:

2

TI-BASIC, 33 bytes on-calculator

"l→Str1:Disp "He..o World!
Str1:Output(2,3,Ans+Ans

Since TI-BASIC uses tokens instead of characters, I limited myself by token. Make sure the screen is cleared before running the program. Note that l and o are two-byte tokens, but w is a sequence variable and d, e, and r are statistics variables, which are all one-byte tokens. This program first Displays the string without the first two l's, and then uses a different command to paste in the other two. Also note that TI-BASIC has no equivalent to a newline, but when the program ends the cursor does move down to allow further input to the calculator.

Hello Goodbye

Posted 2014-01-17T15:39:12.417

Reputation: 442

Oh wait, I used 4 commas. I will have to redo this – Hello Goodbye – 2018-12-31T00:30:10.033

Wait, this doesn't work at all because Disp overwrites Ans. – Hello Goodbye – 2018-12-31T00:39:24.217

Fixed. I now made use of both Str1 and Ans. – Hello Goodbye – 2018-12-31T00:44:37.063

2

LINQPad, C# Expression - 22 chars

"Hello w\x6fr\x006cd!"

Ross Presser

Posted 2014-01-17T15:39:12.417

Reputation: 123

2

PHP, 30 characters

Highly inspired by Vereos's answer.

<?=Hello.' wor'.chr(108),"d!";

Aycan Yaşıt

Posted 2014-01-17T15:39:12.417

Reputation: 121

2

HTML - (16 Chars):

Hello Wor&#108d!

Proper HTML would be to put a ; after &#108 but it still compiles fine. :)

Dozer789

Posted 2014-01-17T15:39:12.417

Reputation: 281

HTML... compiles fine? – Mr Lister – 2014-02-20T11:57:02.870

@MrLister Yes, it compiles fine. It is a good practice to put a ; at the end of it, but it still compiles. – Dozer789 – 2014-02-20T23:40:54.257

Oh wait, now I get it. You're creating .chm files! Sorry I didn't get that the first time. – Mr Lister – 2014-02-21T05:53:00.170

@MrLister, Uh... No. I'm making .htm files. – Dozer789 – 2014-02-21T19:02:12.483

Let's just agree to disagree; that would be easier. – Mr Lister – 2014-02-22T09:39:44.360

@MrLister I don't follow... – Dozer789 – 2014-02-26T01:57:28.630

That's alright, I don't follow either. – Mr Lister – 2014-02-26T07:46:33.313

2

C

q=7103816;
main(){printf("%slo world!%c",&q,2+8);}

Works on little-endian platforms, where 7103816 is encoded the same as Hel\0.

ugoren

Posted 2014-01-17T15:39:12.417

Reputation: 16 527

Missing \n at the end. – mcleod_ideafix – 2014-01-19T02:10:50.430

Thanks @mcleod_ideafix. I was going to simply add \n, but I'm out of ns. Fortunately, I had % and , to spare. – ugoren – 2014-01-19T07:47:08.160

2

Lua - 22 characters

print"Hel\108o World!"

Simple enough, example output

lua -e 'print"Hel\108o World!"'
Hello World!

isidor3

Posted 2014-01-17T15:39:12.417

Reputation: 21

2

Javascript, 19ch

> 'Hello Wor\154d!\n'

Character count:

> "'Hello Wor\154d!\n'".length -> 15 //cough, cheating

> "'Hello Wor\\154d!\\n'".length -> 19

With your choice of return, alert(), or nothing? Man, javascript has too many contexts.

Slightly more interesting: ["He",,'o World\n'].join('l')

1j01

Posted 2014-01-17T15:39:12.417

Reputation: 131

Your correct variant has 4 times \ I think ;) – yo' – 2014-01-30T21:57:53.520

2

C, 41

main(){printf("He%clo world!%c",108,10);}

KARTHIK RA

Posted 2014-01-17T15:39:12.417

Reputation: 131

You're using the character n three times. (main, printf, \n) – Darren Stone – 2014-01-21T08:00:20.150

Good work replacing the \n but your score was wrong. I updated the 33 to 41. – Darren Stone – 2014-01-21T09:16:53.437

2

R

Not gonna win anything, but I didn't see R yet...

'He\154\154o, World!'
'Hello, Wor\154d!'

Gaffi

Posted 2014-01-17T15:39:12.417

Reputation: 3 411

1

Hexish    

0B

Timtech

Posted 2014-01-17T15:39:12.417

Reputation: 12 038

2According to the documentation that prints hello world. We need a capital H, a !, and a newline. Close, but no cigar! – Josh – 2014-01-17T22:21:08.623

1@Josh Closer than you think... it actually prints Hello World! – Timtech – 2014-01-17T22:23:06.997

2Ehm, the Esolang page says that this language falls under the category "Unimplemented". Is that allowed? I mean, are unimplemented languages allowed? – Mr Lister – 2014-01-18T07:12:27.220

3In that case, I will now invent a new language SECODEGOLF where every program consists of a single decimal number, and the output is the solution to the corresponding CodeGolf question. For instance, the program 18721 would print "Hello World!" and a newline. – Mr Lister – 2014-01-18T07:26:30.633

2@MrLister Arguably SECODEGOLF is mostly implemented by this website. (Part of the implementation is crowd-sourced.) And most languages' specifications are only mostly implemented. :) – Eliah Kagan – 2014-01-18T09:17:54.330

1

Haskell, 27

main=print"Hello Wor\108d!"

Twice-check:

import Data.List
main=getContents>>=print.all((<3).length).group.sort

Vektorweg

Posted 2014-01-17T15:39:12.417

Reputation: 301

1

q/kdb [16 chars]

"hel\154o world"

nyi

Posted 2014-01-17T15:39:12.417

Reputation: 448

itym -1"Hel\154o world!"; – Aaron Davies – 2014-01-20T09:35:44.047

1

Node.js - 54 Unicode characters

eval([]+Buffer('consolť.ŬůgĨĢHťŬɬů wɯrɬd!Ģĩ',"ascii"))

console.log outputs a given string and a line shift, unfortunately that initially leaves me with way too many ls and os, so it took some work.

The code creates a buffer from a string and is told to use ascii encoding, this effectively takes all character values mod 256 and stores them in the buffer, the buffer is then added to an empty array, which cause both buffer and array to be converted to string before the addition, an empty array converts to an empty string, and the buffer is implicitly converted using UTF-8 encoding. The result is evaled to produce the desired result.

aaaaaaaaaaaa

Posted 2014-01-17T15:39:12.417

Reputation: 4 365

1

PHP 5.1.2+

<?="\x48".hasH_file(@cRC32b,__FILE__,'« Tý'|5)." wor\X6Cd!";

The code hashes itself to get the remaining characters. Repeats the characters ".\,'_

A tab messes up the formatting. Base64:

PD89Ilx4NDgiLmhhc0hfZmlsZShAY1JDMzJiLF9fRklMRV9fLCfCqwlUw70nfDUpLiIgd29yXFg2Q2QhIjs=

shoghicp

Posted 2014-01-17T15:39:12.417

Reputation: 11

Nice hack, but I count 4 underscores. – aaaaaaaaaaaa – 2014-01-19T18:36:04.340

@eBusiness Five _ actually, and four times " :) – yo' – 2014-01-30T22:20:42.067

1

newLISP

Such a cruel challenge for a Lisp-like language, where so much is possible if only you don't count parentheses... :) But a solution can be found:

 (eval-string(encrypt {`4?3%;=6^9z*9&^m=>*],c;W}{HDMZKOQX~B2OUJ1MJQX1HBF~KU2FZD}))

(81 characters)

which uses the simple encrypt function to pass a command through to the evaluator. The actual command is (println {Hello world!}). (Having "z" and "Z" and "Z" is allowed, according to the comments...:)).

cormullion

Posted 2014-01-17T15:39:12.417

Reputation: 569

1

POSIX shell (Bash et al) - 26 chars

printf 'Hel\x6Co world!\n'

Laurence

Posted 2014-01-17T15:39:12.417

Reputation: 31

1

k/q (25 chars)

-1@.h.uh"Hello wor%6cd!";

works in either k or q

(btw, the validity can be checked elegantly with |/#:'="-1@.h.uh\"Hello wor%6cd!\";")

Aaron Davies

Posted 2014-01-17T15:39:12.417

Reputation: 881

1

PHP I am amazed at how many people give invalid answers without mentioning they are. My attempt, only reusing o" characters twice.

<?Php EchO "Hello wor\154d!";

Edit: fixed thanks to @FireFly: i understood to use each character once. This is no challenge anymore.

Barry Staes

Posted 2014-01-17T15:39:12.417

Reputation: 111

1Wouldn't changing the \X6C into l make it completely valid? I only see one other l in there. – FireFly – 2014-01-23T10:50:25.713

1

Active Server Pages (Classic ASP):

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


Each character is used twice!

To run it, you'll need a web server running IIS.

Save it in the site root with a ".asp" extension, make a HTTP request to the server, and you'll see that the response text is exactly "Hello world!" and a new line:

Hello world!


Edit: You could also use this smaller code:

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

Or this:

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

Toothbrush

Posted 2014-01-17T15:39:12.417

Reputation: 3 197

1

http://esolangs.org/wiki/Hello%2B%2B

H

1 letter is all it takes to print that

qwerty

Posted 2014-01-17T15:39:12.417

Reputation: 11

1

BASH

printf "a\107Vs\x62G8gd29ybGQhCg=="|base64 -d

Udi

Posted 2014-01-17T15:39:12.417

Reputation: 11

1

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!

Edit: I've just posted the same answer here.

Toothbrush

Posted 2014-01-17T15:39:12.417

Reputation: 3 197

0

Tcl, 21 bytes

puts Hello\ wor\x6cd!

Try it online!

sergiol

Posted 2014-01-17T15:39:12.417

Reputation: 3 055

0

SmileBASIC

?@H[1]+@e[!0];CHR$(108);"lo world!

Another solution:

CLS?"He__o world!
LOCATE 2,0?@l[1]*2

12Me21

Posted 2014-01-17T15:39:12.417

Reputation: 6 110

0

c-41

main(){printf("He%clo world!%c",154,10);}

Mhmd

Posted 2014-01-17T15:39:12.417

Reputation: 2 019

Doesn't work in general: http://codepad.org/O09aQhCe - on what platform does character code 186 give you 'll' ?

– Paul R – 2014-01-18T10:33:48.873

In MS-DOS (code page 437 and similar) character with code 186 is double vertical line, used for drawing frames. – AMK – 2014-01-18T12:22:56.067

1It's 38 chars. You missed '!'. Besides, the two vertical bars are not two L's – mcleod_ideafix – 2014-01-19T02:06:40.227

It produces this output: He||o world! I'm using code blocks – Mhmd – 2014-01-19T09:43:37.267

Without ending '\n' this answer contains 35 chars. And output looks wery similar to Hello world!. But this answer may be wroted shorter as main(){puts("He║o world!");} – AMK – 2014-01-19T18:52:58.643

@AMK thanks I guess adding the vertical bars was a bad idea from the first. – Mhmd – 2014-01-19T19:04:02.243

Question states: "exactly outputs the characters Hello world!" – Darren Stone – 2014-01-19T19:32:57.107

@Darren that's why I edited it. – Mhmd – 2014-01-19T19:35:12.070

I don't think you're compiling and running your submission, @user689. When I compile and run your program, I get the output He%clo world!%c. This is expected, since puts does not allow printf style formatting. – Darren Stone – 2014-01-19T19:38:28.257

Oops you are right @Darren – Mhmd – 2014-01-19T19:46:59.503

0

JavaScript 35

With inspiration from @VisioN

alert(atob("SGVsbG8gV29y")+'ld!\n')

WallyWest

Posted 2014-01-17T15:39:12.417

Reputation: 6 949

-1

In C. Choose one of these.

My favourite (crazy but compact in memory):

#include <stdint.h>
printf("%s", (char*)(int32_t[]){1819043144,1870078063,6581362});

For those who like big numbers:

printf("%s", (char*)(int64_t[]){8031924123371070792,43509902450});

Or here the more descriptive versions:

printf("%s", (char*)(int32_t[]){0x6c6c6548,0x6f77206f,0x646c72});
printf("%s", (char*)(int64_t[]){0x6f77206f6c6c6548,0x0a21646c72});

char map:

H  e  l  l     o     w  o     r  l  d  !     <LF>
48 65 6c 6c    6f 20 77 6f    72 6c 64 21    0a
(remember to swap big/little endian bytes when composing)

Btw: why there is no 128 bit integer in C?

printf("%s", (char*)(int128_t[]){0x0a21646c726f77206f6c6c6548});
printf("%s", (char*)(int128_t[]){802616035175250124568770929992}); // string uses only 100 of 128 bits

Daniel Alder

Posted 2014-01-17T15:39:12.417

Reputation: 101

2These don't met the requirements as some characters are used more than twice. Eg ( ) 0 1 2 9 etc etc – Adam Speight – 2014-01-17T22:50:12.553

1When I look at the example in the question, I see print("He%so world!"%(2*'l')) which is 1p 2r 1i 1n 1t 2( 2" 1H 1e 2% etc. Even when I focus to the string I still see 2 o's, so why should my answer follow the rules when the question doesn't? ;-) – Daniel Alder – 2014-01-17T22:57:06.583

printf("%s", (char*)(int32_t[]){1819043144,1870078063,6581362});

( x 3, ) x 3, 1 x 5, 3 x 3, 4 x 4, 6 x 3, 8 x 4 – Adam Speight – 2014-01-17T23:08:49.363

Ok, I see. I misunderstood the specs. But I'm not the only one, when I look at the bash + ruby solutions of SztupY and the solution of cnst – Daniel Alder – 2014-01-18T00:11:43.403

1Just because someone else didn't follow the rules doesn't justify you. – Dozer789 – 2014-01-18T19:11:53.363

-1

AWK and echo

EDIT: fix the extra o's following the note. (thanks ProgramFOX)

echo He: | awk -F: '{print $1,Q,"\157 Wor",Q}' OFS=l ORS=d\!

and thanks awk which give me the option to say "-F" instead of "IFS=" (:-)

Udi

Posted 2014-01-17T15:39:12.417

Reputation: 11

3There are too many spaces, too. after echo, after He:, after |, and so on. – Vereos – 2014-01-21T08:33:26.867

-2

Java

Okay I found this on SO, it doesn't output a big H

Rare sequence of random stream of digits for 2 specific seeds.
Probably fixed out by brute forcing
One of the SO solutions also include a brute forcer to make your own sequences.

System.out.println(randomString(-229985452) + " " + randomString(-147909649) + "!");

And randomString() looks like this

public static String randomString(int i)
{
    Random ran = new Random(i);
    StringBuilder sb = new StringBuilder();
    for (int n = 0; ; n++)
    {
        int k = ran.nextInt(27);
        if (k == 0)
            break;

        sb.append((char)('`' + k));
    }

    return sb.toString();
}

Source: https://stackoverflow.com/questions/15182496/why-does-this-code-print-hello-world

SSpoke

Posted 2014-01-17T15:39:12.417

Reputation: 97

5And this meets the specs, how? I can easily count 3 S's, 3 spaces, 3 2's, etc. – Justin – 2014-01-18T08:05:11.483

-2

Console.Write("He{0}{0}o world", "l");

zircon355

Posted 2014-01-17T15:39:12.417

Reputation: 1

7Can you please state the language? Also, a little explanation will help. – Justin – 2014-01-18T07:03:46.723

obviously C# :) – SSpoke – 2014-01-18T09:27:46.287

7Too many ls, too many os, too many "s, too many es... I guess this needs a revision :P – Vereos – 2014-01-18T12:20:02.017

-2

I think that the only character which is being repeated more than twice is 'l' how about assigning variables

For language C:(Note,i am bad at syntax)

main(){

 char *x=*b='l';

printf("Hel%so wor%sd!",x,b);}

and using them instead of 'l' while printing ??

It's not elegant as the answers already here.But it is fair and simple ?right ??

Ankit Srivastava

Posted 2014-01-17T15:39:12.417

Reputation: 101

Why don't you post a code instead – Mhmd – 2014-01-19T09:45:44.997

Welcome, @AnikitSrivastava. You should submit code to solve the programming challenge or else place your comments under the question itself. – Darren Stone – 2014-01-19T09:49:15.270

@user689 done that .... – Ankit Srivastava – 2014-01-19T10:11:50.277

@DarrenStone okay, i have added the code now. – Ankit Srivastava – 2014-01-19T10:12:14.667

4Cool. But it's not quite valid. You are using the character r three times. Also, please compile your submission to ensure the syntax is valid. Warnings are fine but you have a compile error with the undeclared b. – Darren Stone – 2014-01-19T10:24:03.507

'1' is char, not char *. This simply cannot work (even if the compiler allows it - it's not valid C, and it doesn't do what you think it does (if the compiler allows such nonsense, it will set pointer to 0x00000031, which simply doesn't make any sense)). – Konrad Borowski – 2014-01-19T11:34:19.703

@DarrenStone thanks for pointing that out...... – Ankit Srivastava – 2014-01-19T12:43:13.270

You should use %c instead of %s, l is a character – Mhmd – 2014-01-19T12:57:02.600

@user689 yes thank u i realized that .....i already stated i wasn't that good at syntax :) – Ankit Srivastava – 2014-01-19T13:03:43.370