82
\$\begingroup\$

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!

Wheat Wizard
103k23 gold badges299 silver badges697 bronze badges
asked Jan 17, 2014 at 15:39
\$\endgroup\$
32
  • 25
    \$\begingroup\$ What about the repeated letter o in the "valid" python example. There also these:- " ' ( ) \$\endgroup\$ Commented Jan 17, 2014 at 16:35
  • 15
    \$\begingroup\$ @AdamSpeight what do you mean? The letter is only used twice, as per the specs. \$\endgroup\$ Commented Jan 17, 2014 at 16:37
  • 5
    \$\begingroup\$ @AdamSpeight ... which is literally the same. \$\endgroup\$ Commented Jan 17, 2014 at 16:42
  • 4
    \$\begingroup\$ I think you mean a character should not appear more than twice, that is, it should not be repeated more than once. \$\endgroup\$ Commented Jan 17, 2014 at 18:15
  • 58
    \$\begingroup\$ I guess brainfuck is out of the question... \$\endgroup\$ Commented Jan 17, 2014 at 18:26

70 Answers 70

1
2 3
65
\$\begingroup\$

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)

answered Jan 19, 2014 at 20:59
\$\endgroup\$
9
  • 38
    \$\begingroup\$ +1 for rule bending... "In a language of your choice..." \$\endgroup\$ Commented Jan 19, 2014 at 22:54
  • 4
    \$\begingroup\$ Love it. But how exactly is that a program? \$\endgroup\$ Commented Jan 20, 2014 at 8:42
  • 5
    \$\begingroup\$ Actually you can look at it as a program in a google translate language - for Chinese as its sub-language :) \$\endgroup\$ Commented Jan 20, 2014 at 8:44
  • 2
    \$\begingroup\$ +1. Nice idea. 世界 = Shì jiè = World. 你好 = nǐ hǎo = Hello. "World, Hello!" translates to "Hello World!". It can be golfed down some more: 你好世! \$\endgroup\$ Commented Jan 20, 2014 at 21:56
  • 2
    \$\begingroup\$ can be golfed down further to 喂世! at the expense of ... well, nothing more is really being expended. \$\endgroup\$ Commented Jan 20, 2014 at 23:40
62
\$\begingroup\$

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("S107円VsbG8gV29ybGQhCg".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 'Hello World¡'|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}}
answered Jan 17, 2014 at 17:28
\$\endgroup\$
13
  • 2
    \$\begingroup\$ While 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" \$\endgroup\$ Commented Jan 17, 2014 at 21:07
  • 14
    \$\begingroup\$ @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) \$\endgroup\$ Commented Jan 17, 2014 at 21:10
  • 5
    \$\begingroup\$ On my system I get Hello World? instead of Hello World! \$\endgroup\$ Commented Jan 17, 2014 at 21:20
  • 1
    \$\begingroup\$ @SztupY oh, you're right, my bad. Very clever, I like it! \$\endgroup\$ Commented Jan 17, 2014 at 21:21
  • 1
    \$\begingroup\$ How many bonus points would you get if your duplicate-checker also conformed to the repeating spec? :-) \$\endgroup\$ Commented Jan 17, 2014 at 22:10
45
\$\begingroup\$

HQ9+, 1 char

H

keeping it simple :)

answered Jan 17, 2014 at 15:47
\$\endgroup\$
9
  • 7
    \$\begingroup\$ HQ9+ outputs a comma though ;) \$\endgroup\$ Commented Jan 17, 2014 at 15:48
  • 8
    \$\begingroup\$ I'd still keep your answer out...it is a popularity contest after all, rules are for the wind! \$\endgroup\$ Commented Jan 17, 2014 at 15:53
  • 26
    \$\begingroup\$ @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. \$\endgroup\$ Commented Jan 17, 2014 at 16:24
  • 5
    \$\begingroup\$ @Howard I feel dirty. I upvoted yours and Josh's comment \$\endgroup\$ Commented Jan 17, 2014 at 17:03
  • 23
    \$\begingroup\$ All print Hello World questions are actually who can submit a HQ9+ answer faster questions. \$\endgroup\$ Commented Jan 18, 2014 at 5:49
45
\$\begingroup\$

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.

answered Jan 17, 2014 at 17:19
\$\endgroup\$
11
  • 16
    \$\begingroup\$ If 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. \$\endgroup\$ Commented Jan 17, 2014 at 19:11
  • 6
    \$\begingroup\$ Now I'm disappointed that Emacs doesn't have a M-x hello-world command... \$\endgroup\$ Commented Jan 17, 2014 at 19:34
  • 4
    \$\begingroup\$ Even if it did, that's three ls. \$\endgroup\$ Commented Jan 17, 2014 at 19:35
  • 1
    \$\begingroup\$ You should note that you have to :set nocompatible. \$\endgroup\$ Commented Jan 19, 2014 at 14:15
  • 1
    \$\begingroup\$ Amazing, but myself find using Right not very vim-y. \$\endgroup\$ Commented Jan 19, 2014 at 16:11
44
\$\begingroup\$

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

answered Jan 17, 2014 at 21:19
\$\endgroup\$
4
  • 3
    \$\begingroup\$ Creatively impressive. I like it. \$\endgroup\$ Commented Jan 17, 2014 at 22:48
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 18, 2014 at 6:02
  • 1
    \$\begingroup\$ I think you can easily uncomment . by using it for fractions. Also you can declare an array and use []. \$\endgroup\$ Commented Jan 19, 2014 at 15:18
  • \$\begingroup\$ @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_... \$\endgroup\$ Commented Jan 19, 2014 at 15:29
30
\$\begingroup\$

Piet-- No characters whatsoever!

Hello world in Piet

\$\endgroup\$
5
  • 7
    \$\begingroup\$ I would consider the codels as "characters". \$\endgroup\$ Commented Jan 17, 2014 at 21:16
  • 3
    \$\begingroup\$ @PaŭloEbermann What would you consider to be a unique codel? EG different shapes? colors? sizes? some combination thereof? \$\endgroup\$ Commented Jan 19, 2014 at 19:19
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Mar 7, 2014 at 9:30
  • \$\begingroup\$ @plannapus In that case I don't this challenge is technically possible in Piet. I may come up with something creative though. \$\endgroup\$ Commented Mar 7, 2014 at 17:57
  • \$\begingroup\$ @ValekHalfHeart oh it wasn t a criticism of this answer: i love it! This challenge was not a codegolf anyway. \$\endgroup\$ Commented Mar 8, 2014 at 7:44
27
\$\begingroup\$

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!"
answered Jan 18, 2014 at 14:15
\$\endgroup\$
1
  • 7
    \$\begingroup\$ Um....kinky? +1 :) \$\endgroup\$ Commented Jan 18, 2014 at 14:32
24
\$\begingroup\$

Powershell, 20

"He$('l'*2)o world!"
answered Jan 17, 2014 at 15:53
\$\endgroup\$
0
19
\$\begingroup\$

Sclipting, 11 characters

丟낆녬닆묬긅덯댦롤긐뤊

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

\$\endgroup\$
1
  • 5
    \$\begingroup\$ Whoa! 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) \$\endgroup\$ Commented Jan 20, 2014 at 12:30
18
\$\begingroup\$

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)
answered Jan 17, 2014 at 17:57
\$\endgroup\$
4
  • 4
    \$\begingroup\$ @KCaloux, Since you are allowed up to 2 'l's, wouldn't printf("Hel%co world\n",108) at 28 be even better? \$\endgroup\$ Commented Jan 17, 2014 at 19:11
  • \$\begingroup\$ @MrWonderful I think you're absolutely correct! (Also I just realized that I forgot to include the '!') \$\endgroup\$ Commented Jan 17, 2014 at 19:17
  • \$\begingroup\$ 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!')" \$\endgroup\$ Commented Jan 18, 2014 at 9:58
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Jan 18, 2014 at 16:36
17
\$\begingroup\$

Python 3 [38 bytes]

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

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

answered Jan 17, 2014 at 16:04
\$\endgroup\$
15
\$\begingroup\$

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

answered Jan 17, 2014 at 15:51
\$\endgroup\$
0
15
\$\begingroup\$

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

answered Jan 17, 2014 at 17:53
\$\endgroup\$
9
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 17, 2014 at 18:56
  • 2
    \$\begingroup\$ @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 \$\endgroup\$ Commented Jan 17, 2014 at 19:25
  • 1
    \$\begingroup\$ You can avoid the warning (and save the first .) by putting the Hel before the <?=. \$\endgroup\$ Commented Jan 17, 2014 at 21:23
  • 4
    \$\begingroup\$ @PaŭloEbermann Hel<?=str_rot13("yb jbe")?>ld! \$\endgroup\$ Commented Jan 17, 2014 at 23:47
  • 2
    \$\begingroup\$ @PaŭloEbermann I would say that using that is like cheating, since it's not pure PHP anymore. \$\endgroup\$ Commented Jan 18, 2014 at 0:43
13
\$\begingroup\$

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!"
answered Jan 17, 2014 at 16:03
\$\endgroup\$
7
  • \$\begingroup\$ puts 'He'+'l'*2+'o world!' is one character shorter! \$\endgroup\$ Commented Jan 17, 2014 at 16:38
  • 3
    \$\begingroup\$ But has 6 "'"'s... \$\endgroup\$ Commented Jan 17, 2014 at 16:50
  • \$\begingroup\$ haha I was so focused on letter characters that I never noticed that. never mind! \$\endgroup\$ Commented Jan 17, 2014 at 16:53
  • 1
    \$\begingroup\$ Remove the space after puts and make it 23. -- puts"He#{?l*2}o world!" \$\endgroup\$ Commented Jan 17, 2014 at 17:52
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Jan 17, 2014 at 18:17
13
\$\begingroup\$

HTML Fiddle - 21 characters

Hel&#108;o World!<br>
answered Jan 17, 2014 at 18:29
\$\endgroup\$
6
  • \$\begingroup\$ Does that include the trailing newline? \$\endgroup\$ Commented Jan 17, 2014 at 18:32
  • \$\begingroup\$ Doh...missed that requirement! I'll add a <br> in there. \$\endgroup\$ Commented Jan 17, 2014 at 18:36
  • 7
    \$\begingroup\$ @netinept :It asked for a newline, not a \n so I'd say <br> counts \$\endgroup\$ Commented Jan 17, 2014 at 22:54
  • 1
    \$\begingroup\$ But the character r is repeated in the solution. Did I misinterpret the requirements? \$\endgroup\$ Commented Jan 18, 2014 at 9:59
  • 2
    \$\begingroup\$ "l" and "o" too, but each character can be used twice at most. \$\endgroup\$ Commented Jan 18, 2014 at 14:04
11
\$\begingroup\$

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
answered Jan 17, 2014 at 19:28
\$\endgroup\$
4
  • \$\begingroup\$ Don't you need main etc? \$\endgroup\$ Commented Jan 17, 2014 at 19:28
  • \$\begingroup\$ @FireFly I guess so! It did say to write a program. \$\endgroup\$ Commented Jan 17, 2014 at 19:36
  • \$\begingroup\$ That's C but not C++. C++ does not have implicit int (and you can't spare another i). \$\endgroup\$ Commented Jan 17, 2014 at 19:52
  • \$\begingroup\$ @BenVoigt Okie dokie! \$\endgroup\$ Commented Jan 17, 2014 at 19:56
11
\$\begingroup\$

JavaScript, 66 characters

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

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

answered Jan 18, 2014 at 2:42
\$\endgroup\$
3
  • \$\begingroup\$ I think you are allowed to use some characters just once, and you can drop the comment. \$\endgroup\$ Commented Jan 18, 2014 at 3:19
  • 2
    \$\begingroup\$ @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. :-) \$\endgroup\$ Commented Jan 19, 2014 at 1:22
  • 6
    \$\begingroup\$ +1, but it's easy to use each character exactly twice if you just add gibberish as a comment. \$\endgroup\$ Commented Jan 19, 2014 at 7:32
9
\$\begingroup\$

JavaScript [37 bytes]

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

Too primitive isn't it?

answered Jan 17, 2014 at 16:15
\$\endgroup\$
2
  • 5
    \$\begingroup\$ Where’s the newline? \$\endgroup\$ Commented Jan 17, 2014 at 20:26
  • \$\begingroup\$ @ChristopherCreutzig Sorry, forgot it. Now it is in place. \$\endgroup\$ Commented Jan 19, 2014 at 0:46
9
\$\begingroup\$

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!
%
answered Jan 17, 2014 at 20:40
\$\endgroup\$
7
  • \$\begingroup\$ There are 4 spaces in this solution... \$\endgroup\$ Commented Jan 17, 2014 at 20:54
  • 3
    \$\begingroup\$ @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? :-) \$\endgroup\$ Commented Jan 17, 2014 at 20:58
  • \$\begingroup\$ That works for me! \$\endgroup\$ Commented Jan 17, 2014 at 21:00
  • \$\begingroup\$ @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! \$\endgroup\$ Commented Jan 17, 2014 at 21:13
  • \$\begingroup\$ Very nicely done. \$\endgroup\$ Commented Jan 17, 2014 at 21:15
9
\$\begingroup\$

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

Joe Z.
35.4k14 gold badges66 silver badges165 bronze badges
answered Jan 18, 2014 at 4:10
\$\endgroup\$
1
  • 2
    \$\begingroup\$ I still think vim > emacs. \$\endgroup\$ Commented Jan 18, 2014 at 5:07
6
\$\begingroup\$

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.

answered Jan 18, 2014 at 5:01
\$\endgroup\$
5
\$\begingroup\$

Actually I don't like cheating :P

Python

print("!dlrow os%eH"[::-1]%('l'*2))
answered Jan 17, 2014 at 16:06
\$\endgroup\$
2
  • 2
    \$\begingroup\$ You should specify that it's for python2. In python3 the you get the reversed string as output and then a TypeError. \$\endgroup\$ Commented Jan 18, 2014 at 7:09
  • 1
    \$\begingroup\$ For 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. \$\endgroup\$ Commented Jan 19, 2014 at 16:24
4
\$\begingroup\$

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.

answered Jan 17, 2014 at 16:22
\$\endgroup\$
4
  • \$\begingroup\$ You forgot the "!". \$\endgroup\$ Commented Jan 17, 2014 at 16:27
  • \$\begingroup\$ @Howard, missed it. Oops. \$\endgroup\$ Commented Jan 17, 2014 at 16:31
  • \$\begingroup\$ The letter o is repeated also \$\endgroup\$ Commented Jan 17, 2014 at 16:34
  • 1
    \$\begingroup\$ @AdamSpeight: There is only twice the letter o. The rules say that it's not allowed to have a character more than twice. \$\endgroup\$ Commented Jan 17, 2014 at 16:35
4
\$\begingroup\$

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\x6fr154円d!");}
answered Jan 17, 2014 at 16:50
\$\endgroup\$
5
  • \$\begingroup\$ You still need to output the trailing newline. Doing this challenge in C is difficult... \$\endgroup\$ Commented Jan 17, 2014 at 16:55
  • 1
    \$\begingroup\$ @Josh I just have to use puts() instead of printf(). \$\endgroup\$ Commented Jan 17, 2014 at 16:59
  • 2
    \$\begingroup\$ But what's wrong with o in world? \$\endgroup\$ Commented Jan 17, 2014 at 17:01
  • \$\begingroup\$ @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 code-golf, so I guess it doesn't have to be fixed. \$\endgroup\$ Commented Jan 17, 2014 at 17:08
  • 4
    \$\begingroup\$ In fact, I'm not sure why every answer is displaying a character count. \$\endgroup\$ Commented Jan 17, 2014 at 17:10
4
\$\begingroup\$

BASH

printf 'Hel\x6co world!\n'

Cred @manatwork

echo $'Hel\x6c\x6f world!'
answered Jan 17, 2014 at 18:41
\$\endgroup\$
3
  • \$\begingroup\$ The first one has 3 "e"'s and 3 "o"'s. \$\endgroup\$ Commented Jan 17, 2014 at 18:42
  • \$\begingroup\$ @manatwork: Gag; thanx ;) \$\endgroup\$ Commented Jan 17, 2014 at 18:43
  • \$\begingroup\$ In Bash you may skip -e by using the special $'...' syntax: echo $'Hel\x6c\x6f world!'. \$\endgroup\$ Commented Jan 17, 2014 at 18:48
4
\$\begingroup\$

C - 46 Characters

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

Prints out:

Hello world!
answered Jan 17, 2014 at 19:12
\$\endgroup\$
2
  • \$\begingroup\$ If you're aiming for golf, main(){printf("He%clo world!%c",108,10);} should work, and saves you a few chars. \$\endgroup\$ Commented Jan 17, 2014 at 19:23
  • \$\begingroup\$ @FireFly you're right, you'd save me 3 characters. Your suggestion works perfectly, too. \$\endgroup\$ Commented Jan 17, 2014 at 19:43
4
\$\begingroup\$

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

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You are using three spaces, but I guess this can be fixed removing the ones near the PHP tags! :P \$\endgroup\$ Commented Jan 18, 2014 at 1:05
  • 1
    \$\begingroup\$ That was fast, although I realized before of reading your comment (from another answer actually) \$\endgroup\$ Commented Jan 18, 2014 at 1:07
  • \$\begingroup\$ Isn't the output "H" supposed to be uppercase? \$\endgroup\$ Commented Jan 18, 2014 at 2:47
  • \$\begingroup\$ Completely true, missed that also ): \$\endgroup\$ Commented Jan 18, 2014 at 2:49
4
\$\begingroup\$

XQuery, 19 chars

"Hello Wor&#x6C;d!"
\$\endgroup\$
0
3
\$\begingroup\$

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.

answered Jan 17, 2014 at 16:29
\$\endgroup\$
3
\$\begingroup\$

AWK,34

BEGIN{printf"Hel%co world!\n",108}
answered Jan 17, 2014 at 16:24
\$\endgroup\$
0
1
2 3

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.