Create the shortest possible obfuscated program that displays the text "Hello World".

In order to be considered an obfuscated program, it must meet at least two of the following requirements:

  • Does not contain the characters: h, l, w and d in any case
  • Does not contain the characters: e, o, r, 0, and 1 in any case
  • Does not contain the characters: 2 or 7

Input:
none

Output:
Hello World

  • 5
    I guess import in python is not permitted. – Alexandru Feb 1 '11 at 0:07
  • 25
    Does these rules apply to language keywords as well? – hallvabo Feb 1 '11 at 13:04
  • 7
    are those case insensitive restrictions? – oenone Aug 4 '11 at 14:22
  • 18
    Could someone explain why 2 and 7 are not allowed? I'm just curious as I don't see why those were chosen in particular. – Thomas Eding Aug 5 '11 at 23:01
  • 3
    @trinithis, and others, ASCII character 72 is "H" which is why I chose those two – Kevin Brown Sep 18 '11 at 23:18

118 Answers 118

C (79*12=948)

Using no strings or characters, and only the number one.
I was a little creative with the bitshifts and subtractions to make them fit onto at 80x12 console. Ask me in the comments if you can't figure it out.

int i[(1+1)+1],*I=i;main(){*I++=(((1<<((1<<(1+1))*(1<<(1+1))))+((1<<((((1<<(1<<
(1+1)))-1)^(1<<1+1))-1))-(1<<1)-1+((1<<1)*(1<<1)*(1<<1)*(111-(((1<<(1<<(1+1)))-
1)^(1<<1+1))))))*(((((1<<(1+1))*(1<<(1+1)))*(1<<1)-((1<<(1+1))|1))*(((((1<<(1<<
(1+1)))-1)^(1<<1+1))*((((1<<(1<<(1+1)))-1)^(1<<1+1))-1)*((((1<<(1<<(1+1)))-1)^(
1<<1+1))-1)+(((1<<(1<<(1+1)))-1)^(1<<1+1)))-((((1<<(1<<(1+1)))-1)^(1<<1+1))*(((
(1<<(1<<(1+1)))-1)^(1<<1+1))-1)+1)))+((1<<1)|(1<<(1+1))))+(1<<1));*I++=i[1-(1<<
(1-1))]+(((1<<((((1<<(1<<(1+1)))-1)^(1<<1+1))+(1<<1)))+((1<<(((1<<(1<<(1+1)))-1
)^(1<<1+1)))-(1<<(1+1))*(1<<(1<<1))*((1<<(1<<1))-1)-(1<<1)-1))*(((1<<2)*(1<<2)*
((1<<(1+(1<<(1-1))))-1))*((((1<<(1<<(1+1)))-1)^(1<<1+1))-1)*((((1<<(1<<(1+1)))-
1)^(1<<1+1))-1)+(1<<1)+1));*I++=(((1<<(1<<(1<<(1<<1))))+(1<<(1<<((1<<1)+1)))+((
(((1<<(1<<(1+1)))-1)^(1<<1+1))-1)*(1<<1)+1))*((((1<<(1<<(1+1)))-1)^(1<<1+1))-1)
*((((1<<(1<<(1+1)))-1)^(1<<1<<1))-1)+(1<<((1<<1)*((1<<1)+1)))-(1<<1));puts(i);}

Befunge-93 - 57 characters

554553943346**,"b"3+,366**::,,3+::,48*,699*+,,+,**,**,+,@

Should meet all three requirements.

Perl

my @txt = (
  -38,
  -9,
  -6/3,
  -6/3,
  3/3,
  -468/6,
  -69/3,
  3/3,
  4,
  -6/3,
  -30/3,
);

$\ = "\n";
print map{pack 'C', 330/3 + $_} @txt;

I would have been able to do it without any of the of the "forbidden" characters, except there is no easy way, that I can think of to enable the use of anything other than print or die, without using, at least one of the "forbidden" characters.

use feature 'say' # e
use 5.010; # 10
BEGIN{ $^H{'feature_say'} = !'' } # eh
use Modern::Perl # ero

say ...
use IO::Handle; # e
STDOUT->say( ... )

So the only way is to load a module, that internally loads IO::Handle. Which will indirectly enable the use of STDOUT->say.

C, ??? characters

Not very heavily golfed, but I was going more for obfuscation anyway. Your mileage may vary, you'll probably have to do some crap to get the hardcoded address of printf right. No forbidden characters. You could easily shorten up a lot of stuff by not using different numbers of underscores as variable names and instead using 1 letter things, but I think it looks uglier this way.

int main()
{
    int(*f)(int*,...)=467846797-333333333;
    int _=9-8,__=_<<_,___=__<<_,____=___<<_,_____=____<<_,______=_____<<_,$=_|((_____|____)<<__);

    f("%c", $+(_|__|___)^______);
    f("%c", $+(___));
    f("%c", $+(_|__|____));
    f("%c", $+(_|__|____));
    f("%c", $+(__|___|____));
    f("%c", ______);
    f("%c", $+(__|___|_____)^______);
    f("%c", $+(__|___|____));
    f("%c", $+(_|_____));
    f("%c", $+(_|__|____));
    f("%c", $+(_|__));
    f("%c", ______|_);
}

Befunge-93, 8x6 grid

I know I'm a little late to the party, but I saw the Befunge-93 solutions and decided to see how small I could make one while still following all the rules.

"[uixn"v
Qv:,-9<"
v_vQQQ^)
>9+,>:|f
^Q>>^Q@"
^"?ncu"<

><> (Fish), 80 bytes

Wait, I'm not the only one that uses ><>?

33-aa*:8+:6+:3-8a*843--+48*aa*:b+$8+::843---89*ab*43-+543-p33-43-.
 :?!;_33-43-.

Thanks to @Sp3000 for a method to print without "o".


Try it here.

C (333 characters)

I decided to emphasize on obfuscate, with golf secondary. This is written entirely in C, and it only breaks rule #2 laid out in the original post. It also breaks I don't know how many C programming rules...

int main(){
int a[]={0x0a004000,0x0fc00109,0x04e01500,0x09e08400,0x03506a61,0x00f00000,0x0f010ae3,0x05f0fb16,0x0beb0030,0x0130a300,0x0bc00500,0x00000000};
int b,c=13,e,x,an;
goto _XX;
_00:an=e,x^=x,b^=b;
_10:if(!an)goto _XX;
b|=!!(an&0xf)<<x++;
an>>=4;
goto _10;
_XX:if(c<=1)goto _40;
if(c<13)printf("%c",b);
e=a[13-c--];
goto _00;
_40:return 0;
}

J (23 characters)

a.{~<:a.i.'Ifmmp!Xpsme'

It doesn't beat Golfscript, but I figure J deserves an entry anyway. (This is just a minor tweak of the second example on the J vocabulary page for the word i..

C Program (83 Characters)

#include<stdio.h>
void main(){printf("%ce%c%co %cor%c%c",104,108,108,119,108,100);}

"C++"

329 bytes including newlines and extraneous backslashes on newlines (which are 7 bytes).

C++ is in scare quotes because of all the implementation dependent details (gcc, appropriate linux kernel, x86). Doing this challenge in C++ is difficult because right off the bat #include is forbidden.

int main(){int r[]={1819043144,1866980911+1000000,164353511+10000011};asm("sub \
$31,%%esp\nsub $1,%%esp\nmov $4,%%eax\nmov %%eax,0x1C(%%esp)\nmov %0,%%eax\nmov\
 %%eax,0x18(%%esp)\nmov %1,%%eax\nmov %%eax,0x14(%%esp)\nmov $1,%%eax\nmov %%ea\
x,16(%%esp)\npopa\nint $0x80"::"r"(r),"r"(9+3):"%eax","%ebx","%ecx","%esi",
"%ebx");}

I think there's technically a bit of undefined behavior here as well, since I don't tell gcc all the registers I clobber (Things like %edx cannot be referred to directly) which is unfortunate.

JavaScript 155 142 122

This satisfies ALL the rules provided.

_=(!!4+"")[5-4],3[C="c\x6fnst"+_+"uct\x6f"+_][C]("a\x6c\x65"+_+
"t('\x48\x65\x6c\x6c\x6f \\x5"+-~6+"\x6f'+_+'\x6c\x64')")()
  • 1
    You can do -~[] to get 1. Also, using my approach with constructor twice instead of going via []["sort"] saves you even more: 3[$="c\x6fnst"+(_=(!+[]+"")[-~[]])+"uct\x6f"+_][$] gets you Function and saves 14 chars. – FireFly Jan 20 '14 at 23:08
  • @FireFly, nice spotting... All rules now done in 142 characters... I had to account for the "W"... Damn hard character to get with the restrictions... – WallyWest Jan 21 '14 at 0:54
  • 1
    I took the liberty to edit the post with some more changes, I hope you don't mind... get boolean true via !!4, the number 1 via 5-4, and by making use of double-escaping (once because of the string literal, and then a second time due to the string literal inside the alert in the function body) we could simply concatenate the -~6 into the string instead of having to unescape. – FireFly Jan 21 '14 at 12:31
  • @FireFly As Humphrey Bogart said in Casablanca "This looks like the start of a beautiful friendship." :) But I have to ask, what the hell is the use of the 3? I see ',3[C="' but don't understand the number's importance in the code? – WallyWest Jan 21 '14 at 22:15
  • 1
    Haha. The 3 replaces [] in your code because both numbers and arrays (like all other types constructed via constructor functions) inherit a 'constructor' property from their prototype. It doesn't matter which of these that we use, so I switched to 3 since it saves a character. In the end, it's just a stepping stone to reach Function (as the constructor of the Number function, i.e. Number.constructor). If you want to discuss further we should probably use the chatroom instead... – FireFly Jan 21 '14 at 22:33

Sclipting, 8 characters

낆녬닆묠녶뭲닆밄

Of course, this doesn’t contain any of the restricted characters.

(This answer is technically cheating because Sclipting was invented after this challenge was posted.)

Haskell (genetic programming), 306 chars

This is not really genetic programming. It's just a pun. The only violation of the rules is the function name putStrLn, which is a builtin I/O function, and follows the spirit of the rules even if it doesn't quite match the letter.

a=(['~','}'..]!!)
t=(succ)
y= \x->x-x
c=(y)$3
g=((t.t$c)*)
q=(a.g.t.g.t.g.g.t.g.t$c):(a.t.g.g.g.t.g.t$c):(a.g.t.g.g.g.t$c):(a.g.t.g.g.g.t$c):(a.t.g.t.g.t.g.t$c):(a.g.t.g.t.g.t.g.t.g.g.t$c):(a.t.g.t.g.t.g.g.g.t$c):(a.t.g.t.g.t.g.t$c):(a.g.g.t.g.t$c):(a.g.t.g.g.g.t$c):(a.g.t.g.g.t.g.t$c):[]
main=putStrLn$q
  • +1. But what's the significance of the parens around y on line 4? – YoYoYonnY Jan 30 '16 at 0:15
  • 1
    None whatsoever. I suppose you could shave off a couple extra chars, but this isnt a competitive answer in any case. – archaephyrryx Jan 30 '16 at 4:58

Golfscript 18 bytes

New code (saved 4 bytes thanks to Martin Büttner):

'Jgnnq"Yqtnf'{((}%

Old code (22 bytes):

"Jgnnq\"Yqtnf"{1 1+-}%

It basically preforms a Caesar cipher two times. Because you can't have a 2 in your code, I just used 1+1. It doesn't break any of the rules.

  • (( (decrement twice) is shorter than 1 1+-. Also, does GolfScript support ' to delimit strings? In that case you wouldn't need to escape the " in the string. – Martin Ender Mar 9 '15 at 12:47

Clip, 17 chars

All rules followed.

m+'☻`"Fcjjm▲Umpjb

This just means, in a more readable form, map (add 2 to ascii value) "Fcjjm▲Umpjb".

Pyth - 24 bytes. All 3 rules

Noticed there wasn't a Pyth entry yet (probably because the question's been around longer), but wanted to add one for completion's sake!

V"Qnuux)`x{um"=+kC-CN9;k

Try it out.

Explanation

# basically just a -9 int value translation on each character

V"Qnuux)`x{um"        ;     # for each chr (N) in the string "Qnuux)`x{um"
              =+k           #   append to k (initially an empty string)
                 C          #   the character value of the integer
                  -  9      #   that results from subtracting 9 from
                   CN       #   the integer value of the current chr (N)
                       k    # print k

C 61 Bytes

main(){printf("%ce%c%co %cor%c%c",9*8,108,108,86+1,108,100);}

Went as small as possible on this guy. Hopefully y'all can see that. This breaks rule 2.

  • The rules say you have to comply with two of the three rules. I follow rule 1 and 3 – bioweasel Oct 20 '16 at 19:47

Befunge-93, 49 45 bytes

Thanks to James Holderness for saving me two four bytes! (I don't know how to count)

Why is this 7-year-old challenge in the front page? I don't know! What I do know is that I came up with an answer before I realized the thread is ancient, so here goes:

554**:8+:6+:3-:83*-48*"q"2-:3-::7-"F"2+>:#,_@

Works in complete disregard to the third rule, but that's fine because rules are made to be broken anyway it meets 1 and 2.

Try it online!

Java, 88

I'm surprised, nobody used java.

System.out.print\u006Cn("\u0048e\u006C\u006Co "+((c\u0068ar)(11*8-1))+"or\u006C\u0064");
  • 1) this is not a complete function; 2) byte count is wrong. See my answer. – Andrey Jan 18 '17 at 8:04
  • @Andrey 1) it won't compile, but you can run it in jshell under java 9, as for 2 i fixed it. – user902383 Jan 18 '17 at 8:17

pb, 72 bytes

b[69+3]>b[101]>b[108]>b[108]>b[111]>>b[86+1]>b[111]>b[114]>b[108]>b[100]

Violates rule II

  • oh hey, someone else wrote a pb answer! (i'm a little late) – undergroundmonorail Sep 8 '17 at 6:13
  • @undergroundmonorail hey you're back! (?) – Erik the Outgolfer Sep 8 '17 at 9:16
  • i check this site every day... has it really been that long since i posted anything? o_o – undergroundmonorail Sep 9 '17 at 5:55

C, 2066 bytes

NOTE: Little-endian only. (That should give readers a hint at what this strange code does.)

Certainly not going to win, but it's kinda neat anyway (IMO). Satisfies first and third requirements.

int _(){return 0;}int __(_){return(1+_);}int _____(_
,__){return(_+__);}int ______(_,___){return(_*___);}
int ___(_,__){return _<<__;}int main(){int ____[4]={
___(_____(______(__(___(__(_()),__(_()))),______(__(
___(__(_()),__(__(___(__(_()),__(_())))))),______(_\
____(___(______(__(___(__(_()),__(___(__(_()),__(_()
))))),__(___(__(_()),__(_())))),__(___(__(_()),__(_(
))))),__(__(__(___(__(_()),__(__(_()))))))),__(___(\
__(__(__(___(_____(___(__(_()),__(___(__(_()),___(_\
_(_()),__(_()))))),__(__(__(___(__(_()),___(__(_()),
__(_()))))))),___(__(___(__(_()),__(_()))),__(_())))
))),__(___(__(_()),__(_())))))))),___(__(_()),___(__
(_()),__(_())))),(_____(___(__(_()),__(_())),__(_())
))),______(_____(___(__(___(_____(___(_____(___(__(_
()),___(__(_()),___(__(_()),__(_())))),__(__(__(___(
__(_()),__(___(__(_()),__(_())))))))),___(__(_()),__
(_()))),__(___(__(_()),__(_())))),___(__(_()),__(_()
)))),___(___(__(_()),__(_())),__(_()))),__(___(__(_\
__(__(_()),__(_()))),__(_())))),(_____(___(______(_\
____(___(__(___(__(___(__(___(__(_()),__(_()))),__(_
()))),__(_()))),___(___(__(_()),__(_())),__(_()))),\
__(___(__(_()),__(_())))),__(___(______(__(___(__(_(
)),__(_()))),______(__(___(__(_()),___(__(_()),__(_(
))))),__(___(__(___(__(_()),__(_()))),__(_()))))),__
(_())))),___(__(_()),__(_()))),(__(___(__(_()),___(\
__(_()),__(_())))))))),______(__(__(__(___(__(_()),\
__(___(__(_()),__(_()))))))),______(__(______(___(__
(_()),__(_())),______(__(___(__(_()),__(_()))),__(_\
__(__(_()),___(__(_()),___(__(_()),__(_())))))))),__
(___(__(___(______(__(___(__(___(__(___(__(___(__(_(
)),__(___(__(_()),__(_()))))),___(__(_()),__(_()))))
,__(_()))),__(_()))),__(______(___(__(_()),__(_())),
______(__(___(__(_()),__(_()))),______(__(___(___(__
(_()),__(_())),__(_()))),__(___(__(___(___(__(_()),\
__(_())),__(_()))),__(___(__(_()),__(_())))))))))),\
___(__(_()),__(_())))),__(_()))))),__(___(__(___(__(
___(___(__(_()),__(_())),__(_()))),___(___(__(_()),\
__(_())),__(_())))),__(___(___(__(_()),__(_())),__(_
())))))};printf("%s",____);return(______(_(),_()));}
  • 1
    Yes, but the original problem statement stipulated that answers "...must meet at least two of the following [3] requirements." Mine does this. – pr1268 Jan 27 '17 at 18:18
  • 1
    @pr1286 Sorry, my bad, goes to show everyone is capable of misreading questions. Anyway the welcoming to the site still stands. – 0 ' Jan 27 '17 at 22:45
  • 2
    Oh my, CFuck? I didn't know such a thing existed. – lol Mar 31 '17 at 8:05

17, 80 bytes

It isn't much bigger than the normal hello world for 17 due to it using base 17. I have to break rule 3 since the "main" function for 17 is 777, so all 17 programs must contain 7, so I am following the other 2.

777{44 $ 5g $ 66 : : $ $ 69 : $
22 4 - $ 52 $ $ 6c $ $ 5f $ 22 3 - $ a $ - @}
  • Welcome to PPCG! Nice first post! Is that your language as well? – Picard Feb 4 at 18:33
  • Thanks, yes, I made 17, though not for this challenge – Hugh Williams Feb 4 at 18:42

FSharp, 83

("(())(((()("|>String.mapi(fun i c->" =CCG/GJC<".[i]+c)).Insert(5," ")|>printf "%s"

Breaks the second rule to use some F# keywords.

Groovy - 50 93 96 Characters

'GdkknVnqkc'.bytes.each{System.out<<(char)(it+1)}

Breaks rule 2. I don't see any other option than breaking rule 2, as AFAIK it's necessary to use either System.out or println, and using println will break both rules 1 and 2.

Edit:

s={k,v->for(;v>0;v>>=6)System.out<<(k-(v&63) as byte[])}
s 113,34886441
s 48,16
s 130,509150443

Second attempt: much longer, more obfuscated, and hopefully passes all the rules!

Rule Check:

['2','7','H','h','L','l','W','w','D','d'].collect{
    it in ("""s={k,v->for(;v>0;v>>=6)System.out<<(k-(v&63) as byte[])}
    s 113,34886441
    s 48,16
    s 130,509150443""" as List)
}
  • Also breaks rule 1, because "char" contains an "h". – Luigi Plinge Nov 20 '11 at 15:54
  • ouch, will take a look – Armand Nov 20 '11 at 18:15
  • each breaks rules 1 and 2 ... but they are pretty stupid rules, IMO – Luigi Plinge Nov 21 '11 at 17:53
  • @Luigi good point - have removed each, and corrected the rule check so it actually works – Armand Nov 22 '11 at 6:43

BrainFuck (96 char)

Beside @R. Martinho Fernandes's BrainFuck answer, this is another BF program with 10 less characters

++++++++++[>++++++++++>+++<<-]>++++.---.+++++++..+++.>++.<++++++++.--------.+++.------.--------.
  • 1
    I say this fails, it outputs "hello world" not "Hello World". – user3710044 Mar 5 '15 at 8:48

Q (40 chars)

Silly answer but it satisfies rule 1 & 2

"c"$(+\)(8*9;10+19;6+1;0;3;10-89;55;10+14;3;-6;-8)

APL (157 155)

No h, l, r, w, d, 2, 7, e, o, or r, but there is 0 and 1 (so it meets two out of three requirements).

I went for obfuscation rather than size. (If you can't figure out how it works, it is a variation of this guy's method).

⎕UCS{⌈+/96,⍵{⊃a×b○c×1.118×⍺,a b c←⍵}¨,⌿((11-33)13.3 ¯8.5 18(.3×4)16.5 4 8.5 .4 6,[0]10⍴(⍴'⍴⍴')1),[1]⌈.5×⍳10}¨(⍳11)-1

APL (28)

Boring straightforward one, but meets all requirements and is short-ish.

⎕UCS(⎕UCS'Jgnnq"Yqtnf')-.5×4
  • +1 That's a great link. But your code's greek to me. :) (Don't worry, I'll get there. Just got some Iverson from Amazon.) – luser droog Apr 10 '13 at 3:58
  • Save a byte on the bottom one with -⍴⍬⍬ – Adám Jul 20 '16 at 15:55

Processing, 189 characters

int[]z={104,101,108,108,111,119,111,114,108,100};for(int i=0;i<z.length;i++)if(i==0||i==5)print((char)Character.toUpperCase(z[i]));else if(i==4)print((char)z[i]+" ");else print((char)z[i]);

If I'm not mistaken, this program only violates rule number two... unless of course the 'h' in "Character" is ruled as a violation. First post to CodeGolf!

Ungolfed

int[] z = {104, 101, 108, 108, 111, 119, 111, 114, 108, 100};

for (int i = 0; i < z.length; i++)
{
    if (i == 0 || i == 5) print((char) Character.toUpperCase(z[i]));
    else if (i == 4) print((char) z[i] + " ");
    else print((char) z[i]);
}
  • 1
    Yes, h is a violation. – pts Aug 24 '13 at 6:59
int main()
{printf("%c%c%c%c%c%c%c%c%c%c%c", ('C'+5), ('a'+4), ('i'+3), ('f'+6), ('i'+6), (35-3), ('T'+3), ('j'+5), ('k'+7), ('g'+5), ('f'-2));}

Javascript 54

(Violates only rule 3)

c="c\x6fnst\x72uct\x6f\x72",f=""[c][c],f("a\x6c\x65\x72t(\"\x48\x65\x6c\x6c\x6f \x57\x6f\x72\x6c\x64\")")()

Test if any character of rule 1,2 contained

/[hlwdeor01]/ig.test('c="c\\x6fnst\\x72uct\\x6f\\x72",f=""[c][c],f("a\\x6c\\x65\\x72t(\\"\\x48\\x65\\x6c\\x6c\\x6f \\x57\\x6f\\x72\\x6c\\x64\\")")()') // false

protected by Community Dec 9 at 22:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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