79
\$\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!

\$\endgroup\$
  • 24
    \$\begingroup\$ What about the repeated letter o in the "valid" python example. There also these:- " ' ( ) \$\endgroup\$ – Adam Speight Jan 17 '14 at 16:35
  • 15
    \$\begingroup\$ @AdamSpeight what do you mean? The letter is only used twice, as per the specs. \$\endgroup\$ – Josh Jan 17 '14 at 16:37
  • 5
    \$\begingroup\$ @AdamSpeight ... which is literally the same. \$\endgroup\$ – VisioN Jan 17 '14 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\$ – Michael Kay Jan 17 '14 at 18:15
  • 56
    \$\begingroup\$ I guess brainfuck is out of the question... \$\endgroup\$ – jubobs Jan 17 '14 at 18:26

71 Answers 71

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.

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

AWK,34

BEGIN{printf"Hel%co world!\n",108}
\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
  • 1
    \$\begingroup\$ Unfortunately your code has three e's and three l's! \$\endgroup\$ – Josh Jan 17 '14 at 18:13
  • 1
    \$\begingroup\$ One of the duplicate l's can be removed easily. e is harder, unless nginx is case-insensitive \$\endgroup\$ – SztupY Jan 17 '14 at 18:20
  • 4
    \$\begingroup\$ Don't forget the spaces! \$\endgroup\$ – Vereos Jan 17 '14 at 18:52
  • 1
    \$\begingroup\$ And 3×'r', as well \$\endgroup\$ – Joel Purra Jan 19 '14 at 14:22
3
\$\begingroup\$

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!

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

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – FireFly Jan 18 '14 at 10:37
  • 1
    \$\begingroup\$ But 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. \$\endgroup\$ – Bob Jarvis Jan 18 '14 at 12:40
  • \$\begingroup\$ 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) \$\endgroup\$ – KChaloux Jan 18 '14 at 16:41
3
\$\begingroup\$

Perl, 28 chars

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

Rules tested with:

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

C (32 characters)

main(){puts("He\x6clo world!");}
\$\endgroup\$
3
\$\begingroup\$

Яussian

Хелло мир!

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

\$\endgroup\$
  • \$\begingroup\$ 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! \$\endgroup\$ – Vereos Jan 20 '14 at 11:44
  • \$\begingroup\$ @Vereos thanks :) \$\endgroup\$ – Indoor Jan 24 '14 at 0:53
3
\$\begingroup\$

Plain TeX - 18 chars

He^^,lo world!\bye

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

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

LINQPad, C# Expression - 22 chars

"Hello w\x6fr\x006cd!"
\$\endgroup\$
2
\$\begingroup\$

PHP, 30 characters

Highly inspired by Vereos's answer.

<?=Hello.' wor'.chr(108),"d!";
\$\endgroup\$
2
\$\begingroup\$

HTML - (16 Chars):

Hello Wor&#108d!

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

\$\endgroup\$
  • \$\begingroup\$ HTML... compiles fine? \$\endgroup\$ – Mr Lister Feb 20 '14 at 11:57
  • \$\begingroup\$ @MrLister Yes, it compiles fine. It is a good practice to put a ; at the end of it, but it still compiles. \$\endgroup\$ – Dozer789 Feb 20 '14 at 23:40
  • \$\begingroup\$ Oh wait, now I get it. You're creating .chm files! Sorry I didn't get that the first time. \$\endgroup\$ – Mr Lister Feb 21 '14 at 5:53
  • \$\begingroup\$ @MrLister, Uh... No. I'm making .htm files. \$\endgroup\$ – Dozer789 Feb 21 '14 at 19:02
  • \$\begingroup\$ Let's just agree to disagree; that would be easier. \$\endgroup\$ – Mr Lister Feb 22 '14 at 9:39
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Missing \n at the end. \$\endgroup\$ – mcleod_ideafix Jan 19 '14 at 2:10
  • \$\begingroup\$ Thanks @mcleod_ideafix. I was going to simply add \n, but I'm out of ns. Fortunately, I had % and , to spare. \$\endgroup\$ – ugoren Jan 19 '14 at 7:47
2
\$\begingroup\$

Lua - 22 characters

print"Hel\108o World!"

Simple enough, example output

lua -e 'print"Hel\108o World!"'
Hello World!
\$\endgroup\$
2
\$\begingroup\$

C, 41

main(){printf("He%clo world!%c",108,10);}
\$\endgroup\$
  • \$\begingroup\$ You're using the character n three times. (main, printf, \n) \$\endgroup\$ – Darren Stone Jan 21 '14 at 8:00
  • \$\begingroup\$ Good work replacing the \n but your score was wrong. I updated the 33 to 41. \$\endgroup\$ – Darren Stone Jan 21 '14 at 9:16
2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Your correct variant has 4 times \ I think ;) \$\endgroup\$ – yo' Jan 30 '14 at 21:57
2
\$\begingroup\$

R

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

'He\154\154o, World!'
'Hello, Wor\154d!'
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ For 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. \$\endgroup\$ – FireFly Jan 20 '14 at 9:55
  • \$\begingroup\$ @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 :) \$\endgroup\$ – Tomas Jan 20 '14 at 9:59
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Oh wait, I used 4 commas. I will have to redo this \$\endgroup\$ – Hello Goodbye Dec 31 '18 at 0:30
  • \$\begingroup\$ Wait, this doesn't work at all because Disp overwrites Ans. \$\endgroup\$ – Hello Goodbye Dec 31 '18 at 0:39
  • \$\begingroup\$ Fixed. I now made use of both Str1 and Ans. \$\endgroup\$ – Hello Goodbye Dec 31 '18 at 0:44
1
\$\begingroup\$

Hexish    

0B
\$\endgroup\$
  • 2
    \$\begingroup\$ According to the documentation that prints hello world. We need a capital H, a !, and a newline. Close, but no cigar! \$\endgroup\$ – Josh Jan 17 '14 at 22:21
  • 1
    \$\begingroup\$ @Josh Closer than you think... it actually prints Hello World! \$\endgroup\$ – Timtech Jan 17 '14 at 22:23
  • 2
    \$\begingroup\$ Ehm, the Esolang page says that this language falls under the category "Unimplemented". Is that allowed? I mean, are unimplemented languages allowed? \$\endgroup\$ – Mr Lister Jan 18 '14 at 7:12
  • 3
    \$\begingroup\$ In 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. \$\endgroup\$ – Mr Lister Jan 18 '14 at 7:26
  • 2
    \$\begingroup\$ @MrLister Arguably SECODEGOLF is mostly implemented by this website. (Part of the implementation is crowd-sourced.) And most languages' specifications are only mostly implemented. :) \$\endgroup\$ – Eliah Kagan Jan 18 '14 at 9:17
1
\$\begingroup\$

Haskell, 27

main=print"Hello Wor\108d!"

Twice-check:

import Data.List
main=getContents>>=print.all((<3).length).group.sort
\$\endgroup\$
1
\$\begingroup\$

q/kdb [16 chars]

"hel\154o world"
\$\endgroup\$
  • \$\begingroup\$ itym -1"Hel\154o world!"; \$\endgroup\$ – Aaron Davies Jan 20 '14 at 9:35
1
\$\begingroup\$

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.

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

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=

\$\endgroup\$
  • \$\begingroup\$ Nice hack, but I count 4 underscores. \$\endgroup\$ – aaaaaaaaaaaa Jan 19 '14 at 18:36
  • \$\begingroup\$ @eBusiness Five _ actually, and four times " :) \$\endgroup\$ – yo' Jan 30 '14 at 22:20
1
\$\begingroup\$

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

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

POSIX shell (Bash et al) - 26 chars

printf 'Hel\x6Co world!\n'
\$\endgroup\$
1
\$\begingroup\$

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

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

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

H

1 letter is all it takes to print that

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

BASH

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

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

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Wouldn't changing the \X6C into l make it completely valid? I only see one other l in there. \$\endgroup\$ – FireFly Jan 23 '14 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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