Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Dilbert is awesome

I'm hoping to add a new twist on the classic "Hello World!" program.

Code a program that outputs Hello World! without:

  1. String/Charachter literals
  2. Numbers (any base)
  3. pre-built functions that return "Hello World!"
  4. RegEx literals

With the exceptions of "O" and 0.

†"O" is capitalized, "o" is not acceptable.

share|improve this question
3  
One of [code-golf] and [code-challenge] please, not both. The point of these tags to to help people find questions with the rules they want to use. Essentially every question on this site should be a game of some kind or another. – dmckee Mar 11 '11 at 22:29
1  
-1 We've already had Obfuscated Hello World, and I think this challenge is too similar. I'd have cast a "close as duplicate" vote, if I weren't a mod. – Chris Jester-Young Mar 11 '11 at 22:35
2  
@zzzzBov: I don't think it's different enough to warrant another question in the "hello world" theme; a different theme would have been better. But, that's just my opinion. – Chris Jester-Young Mar 11 '11 at 23:39
1  
I think this is a fine code golf - and better than the prior one. – MtnViewMark Mar 12 '11 at 6:58
2  
Some people seem to assume that "O"* means they can have a string literal with any number of O’s, including zero. I don’t think that was the intention. Please clarify. – Timwi Mar 12 '11 at 21:12
show 7 more comments

46 Answers

1 2
up vote 21 down vote accepted

Windows PowerShell, way too much

Yes, indeed, back in the day we had to write a »Hello world« using (almost exclusively) zeroes ...

&{-join($args|%{[char]$_.Length})} `
O00000000000000000000000000000000000000000000000000000000000000000000000 `
O0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O0000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 `
O00000000000000000000000000000000

On a more serious note:

Windows PowerShell, 25

Write-Host Hello World!

No string literal. The Hello World! in there just happens to be parsed as a string since PowerShell is in command parsing mode there.

share|improve this answer
2  
How is that real?? O_o – Josh Mar 11 '11 at 22:06
1  
+1 for so many zeros – zzzzBov Mar 12 '11 at 2:07
1  
I searched the internet for some examples or history of this. This is so weird. Could you provide any links? – Caleb Jares Dec 5 '11 at 5:44

Tcl

In Tcl, everything is a string.

puts Hello\ World!

If you disallow this, then this is the only valid Tcl program that can be written:

share|improve this answer

Lua, 36

print(next{Hello=0},(next{world=0}))
share|improve this answer

Python, 110

def HelloOWorld():B
def B(a):print HelloOWorld.__name__.replace('O',chr(a+~0))+chr(a)
B(ord(B.__name__)>>-~0)
share|improve this answer

Python3, 16 bytes

import __hello__

Note the rule:

pre-built functions that return "Hello World!"

Does not apply since:

  1. That's an import and not a function
  2. It doesn't return anything
  3. It doesn't return the string but simply prints it.
share|improve this answer

Groovy, 117

def propertyMissing(p){p}
b="OOOOOOOO"
c={(char)it.size()}
a=b+b+b+b
println(Hello+c(a+b+"OOOO")+c(a)+World+c(a+"O"))

prints

Hello, World!
share|improve this answer

Perl, 96 chars

sub AUTOLOAD{my$x++;$y=$x<<$x++;print substr($AUTOLOAD,$x+$y).chr(($x<<$y)+$a++)}
&Hello;&World

It passes the rules!

share|improve this answer

Ruby 45 chars

p [:Hello,:World!].join :_20[-~0..~0].hex.chr
share|improve this answer
or :HelloWorld!.to_s.titleize in rails (26 chars) – Mikey Mar 20 at 14:37

Python, 106

o=-~-~-~0
L=o+o
d,W=-~L,o**o
_=o*W
print str().join(chr(L+W+_-i)for i in[d*L,L+d,L,L,o,-~_,W,o,0,L,d+d,_])
share|improve this answer
Use '' (with no preceding space) instead of str() – aditsu Mar 19 at 11:29
1  
Also, VERY nice! :) Btw, the multiple assignment is not saving any characters – aditsu Mar 19 at 11:39
@aditsu: I can't, that would be a string literal. Thanks for your comments. :) – flornquake Mar 20 at 14:49
Oh oops, somehow the empty string didn't register as a literal in my mind – aditsu Mar 20 at 15:23
+1. Should be easy to port to Perl. – Steven Rumbalski Mar 20 at 16:05

Java - 147, no literals

class HelloCWorlds{static{char[]a=HelloCWorlds.class.getName().toCharArray();int
x=a.length,y=a[--x]%x;a[y]/=x/y;a[x]=a[y]--;System.out.print(a);}}

Run it like this (after compiling):

java HelloCWorlds 2>/dev/null

If you don't want to ignore stderr, then add System.exit(0); after the last semicolon. It brings the file size to 162 and makes use of the 0 literal.

share|improve this answer
Nice trick! Just one thing to mention: not works with OpenJDK. pastebin.com/gxE7PrjX – manatwork Mar 19 at 8:42
@manatwork Hmm I think it's not about OpenJDK, but about java 6 vs 7 – aditsu Mar 19 at 8:55
Possible. BTW, I dug out an old “java version "1.4.2_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)” to test this – also works fine. – manatwork Mar 19 at 9:04

Common Lisp, 35

I think nobody tried Common Lisp. Strictly speaking, a symbol is not a string literal, so this is valid:

(print(symbol-name'|Hello World!|))

Second-short if you count the Mathematica one.

share|improve this answer

Haskell - 143 characters

o%y=o.o.o$y;o&y=(o%)%y;o!y=o$o$(o%)&y
r=succ;w=pred;a=r%y;e=r$w&l;l=r!'O';o=r e;u=(w&)&a;y=r%l
main=putStrLn[w!o,o,l,l,y,w u,w$r&'O',y,a,l,e,u]

oy, that was woolly!

No numbers, no numeric operations, variables renamed for amusement.

Some exposition might be nice:

  • o%y, o&y, and o!y each applies the function o to y multiple times: 3, 9, and 29 times respectively. 29?!?! Yes, 29!
  • r and w are next and previous character, which when applied using the above higher- order functions can be made to get all the characters needed from 'O'.

The sequence of jumps needed is:

'O' +29    -> 'l'
'O'  +9 -1 -> 'W'
'l'  -9 +1 -> 'd'
'l'  +3    -> 'o'
'd'  +1    -> 'e'
'o'  +3    -> 'r'
'e' -29    -> 'H'
'r' -81    -> '!'
'!'  -1    -> ' '

  • Edit: (134 -> 144) Forgot to output an exclamation point, sigh....
  • Edit: (144 -> 143) Removed a unnecessary $, renamed # to ! for Hugs.
share|improve this answer
o rly? o.o .... – Joey Adams Mar 12 '11 at 7:12
It doesn't work. codepad.org/lyKyj1Ox – nyuszika7h Mar 13 '11 at 15:31
@Nyuszika7H That's because this service turns on some compiler options by default. It should compile with plain GHC. – FUZxxl Mar 13 '11 at 16:10
@Nyuszika7H It works just fine with GHC. The problem is that that service is using Hugs from 2006. There appear to be two things that Hugs can't deal with: 1) Using '#' as an operator. Changing to '!' makes it work. 2) The definitions of r=succ and w=pred run afoul of how Hugs implements the monomorphism restriction. Changing to r x=succ x and w x=pred x makes it work (at the cost of 4 characters). These seem to be problems in Hugs. – MtnViewMark Mar 13 '11 at 18:09

C# (131 chars)

141 chars 142 chars

enum X{Hello,World,A,B=A<<A<<A}class Y{static void Main(){var c=(char)X.B;System.Console.Write(X.Hello.ToString()+c+++X.World+c);}}

Readable:

// Define some constants (B = 32)
enum X { Hello, World, A, B = A << A << A }
class Y
{
    static void Main()
    {
        // Generate the space (character #32)
        var c = (char) X.B;

        // Remember that “!” is character #33
        System.Console.Write(X.Hello.ToString() + c++ + X.World + c);
    }
}
share|improve this answer
1  
this is twisted and nice. I love it. – jcolebrand Mar 14 '11 at 16:33

JavaScript 654 chars

O=[[,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[],[,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]];for(O_O=0;O.length>O_O;O_O++)document.write(String.fromCharCode((O[O_O].length||-Math.pow([,,].length,[,,,,,].length)-[,,,,,,,].length)+Math.pow([,,].length,[,,,,,,].length)+Math.pow(++[,].length,[,,,].length)-[,].length));document.write(String.fromCharCode(Math.pow([,,].length,[,,,,,].length)+[,].length))

What about abusing array literals just to have unary base. This program has advantage of not using 0.

share|improve this answer
While this may be valid, this particular puzzle is a code golf, which means you should be aiming for the shortest code possible. At 600+ chars, you're nowhere near the <100 chars that the existing JS solutions already have. – zzzzBov Nov 20 '12 at 15:01
@zzzzBov: I'm actually not trying to win. – GlitchMr Nov 20 '12 at 15:02

JavaScript, 88

t=!0<<-~-~-~-~!0
r=[]
for(i in{Hello:"O",World:0})r+=i+String.fromCharCode(t++)
alert(r)

99

Many thanks to @Timwi for the suggestions

removed ternary operator:

o={Hello:"O",World:0}
t=!0<<-~-~-~-~!0
c=String.fromCharCode
r=c(0)
for(i in o)r+=i+c(t++)
alert(r)

103
aliased String.fromCharCode

o={Hello:"O",World:0}
t=!0<<-~-~-~-~!0
c=String.fromCharCode
for(i in o)o[i]?r=i+c(t):alert(r+i+c(++t))

117
Switched if-else to ternary operator

o={Hello:"O",World:0},t=!0<<-~-~-~-~!0
for(i in o)o[i]?r=i+String.fromCharCode(t):alert(r+i+String.fromCharCode(++t))

125
I'm keeping the "O" just to have an "O" in the program.

o={Hello:"O",World:0},t=!0<<-~-~-~-~!0
for(i in o)if(o[i])r=i+String.fromCharCode(t)
else alert(r+i+String.fromCharCode(++t))

133

o={Hello:"O",World:0},t=!0<<(!0+!0<<!0)+!0
for(i in o)if(o[i])r=i+String.fromCharCode(t)
else r+=i+String.fromCharCode(t+!0)
alert(r)
share|improve this answer
@Joey, that's largely the point. – zzzzBov Mar 11 '11 at 23:35
@Joey, i read on the codegolf meta that one should avoid answering their own question for some time to encourage others to try various different approaches. My plan was to uncomment it in a day or two. – zzzzBov Mar 11 '11 at 23:43
@Joey, wasn't working on my own machine at the time, and I didn't feel like e-mailing myself the answer when I could just post it in a comment. – zzzzBov Mar 11 '11 at 23:57
@Joey: "There are only five of those" is wrong. Anyone can suggest an edit. Just click on "edit" between "link" and "flag" and you can see the code. – John Mar 12 '11 at 3:57
@zzz: "that's largely the point" Anyone can still see it. Anyone can suggest an edit by clicking on "edit" in between "link" and "flag", which will bring up the edit dialog, revealing your code. – John Mar 12 '11 at 3:59
show 6 more comments

JavaScript 100 chars (when all in one line)

Borrowing subtly from zzzzBov -- with regard to the -~ trick, not seen that before :) -- this is another way to source those pesky space and exclamation characters.

Relies on the Function.toString() ability:

c=!0<<-~-~!0;a=[];
for(i in{Hello:0,world:"O"}){a+=i+([]+function(){!0}).charAt(c);c+=c>>!0}
alert(a)

JavaScript 89 chars (when all in one line)

Also zzzzBov could slightly improve the first example by using the fact that arrays in JS collapse down to strings when used in a calculation; oh, and not creating needless vars ;)

t=!0<<-~-~-~-~!0;r=[];for(i in{Hello:"O",World:0})r+=i+String.fromCharCode(t++);alert(r)
share|improve this answer

C, 190 189 204

a,b,c,h,e,l,o;i[4],*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);}
  • Must be run with exactly zero command line arguments since it depends on argc being equal to 1.
  • no preprocessor macros
  • Might be system endian dependant (involves cast from integer array to char array)
  • Not memory safe
a,b,c,h,e,l,o;   // variables
i[],m,*j=i;      // array and pointer

main(_)          // if no arguments are given _ will be 1
{
    o=*"O";      // our one legal string constant
    a=_+_+_;     // a = 3
    b=_<<a;      // b = 8
    c=b*a+b;     // c = 32
    h=(o>>_)^o;  // h = 'h'
    o^=c;        // o = 'o'
    e=h-a;       // e = 'e'
    l=o-h+e;     // l = 'l'
    *j++=h-c|e<<b|l<<b+b|l<<c-b;     // j[0] = 'H' | 'e' << 8 | 'l' << 16 | 'l' << 24
    *j++=o|c<<b|o+b-c<<b+b|o<<c-b;   // j[1] = 'o' | ' ' << 8 | 'W' << 16 | 'o' << 24
    *j=o+a|l<<b|e-_<<b+b|c+_<<c-b;   // j[2] = 'r' | 'l' << 8 | 'd' << 16 | '!' << 24

    puts(i);     // puts("Hello World!\0\0\0\0")
}

Revisions:

a,b,c,h,e,l,o;i[9],*j=i;main(_){o=*"O";a=_<<_|_;b=_<<a;c=_<<b-a;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h^c|e<<b|l<<b<<b|l<<(c-b);*j++=o|c<<b|(o+b^c)<<b<<b|o<<(c-b);*j=o+a|l<<b|e-_<<b<<b|c+_<<(c-b);printf(i);} /* original */
a,b,c,h,e,l,o;i[4],*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);} /* golfed better */
a,b,c,h,e,l,o;i[],m,*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);} /* removed illegal numeric literal in array size */
share|improve this answer
i[9] violates the rules. – ugoren Nov 9 '12 at 18:15
shoot, it does doesn't it. – Wug Nov 9 '12 at 18:26
i['O'] should be fine. Or i[-~-~-~-~0]. – ugoren Nov 9 '12 at 21:05
The way that's there works (with the caveat that it starts scribbling over other global variables, but they're not read from again later so I don't care). I could probably reorder them to specifically take advantage of this behavior and make them only overwrite variables that are from-then-on unused. Anyway, at this point it contains no numeric literals and I rather like it that way. – Wug Nov 9 '12 at 21:57

BrainFuck, 102 111 characters

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

Meets all of the rules.

share|improve this answer
I can't decide if the rules should also state 0 and/or "O" must be used. It's a little mean to BrainFuck and golfscript, but they don't exactly have a hard time with this challenge. – zzzzBov Mar 11 '11 at 21:32
13  
@zzzzBov: If they must be used, then Brainfuck code will just include them. They don't affect the program at all, though. – Joey Mar 11 '11 at 21:47

Scala 159

val o='O'/'O'
val t=o+o
val d=t+o
val f=t*t
val e=f*t
val l=' '-d
println (List(-e+o,d*e-t,l,l,' ',-'/',e,' ',' '+d,l,(e-1)*d).map(x=>(x+'O').toChar).mkString)

ungolfed:

val one='O'/'O'
val two=one+one
val drei=two+one // tri, three
val four=two*two
val eight=four<<one

val l=' ' - drei
val h=List(-eight+one, four*eight-two, l, l, ' ', -'/'+one, eight, ' ', ' ' + drei, l, (eight-1)*drei)
println (h.map (x=> (x + 'O').toChar).mkString)
share|improve this answer

C - 125 128 chars

I didn't see a proper C entry so I wrote this one:

main(){char u='O'/'O',t=u+u+u,h=u<<t,s=h<<u+u,d='O'*'O'+t,l=d+h,o='O'|s,
g['O']={'O'-h+u,d+u,l,l,o,s,o+h,o,o+t,l,d,s+u};puts(g);}

(As noted below, redefining u via main(u) can save another 9 bytes.)

share|improve this answer
2  
Your array isn't NULL-terminated, so it prints junk. Pay 2 chars. Earn them back, and more, by main(u) instead of 'O'/'O'. – ugoren May 8 '12 at 6:58

GolfScript, 63 chars

[0))):O.)?O.*-.O.?+)).O.*+((..O+.O(.O+?.O-O*@.O+O.+$.O.*-).O/]+

What, no GolfScript entry yet?

This one uses a single numeric literal 0 and a variable named O (which is used to store the number 3). Everything else is arithmetic and stack manipulation. The string Hello World! is built up from its ASCII codes, character by character.

Here's how it works:

[             # insert start-of-array marker
  0))):O      # increment 0 thrice to get 3, and save it in the variable O
  .)?O.*-     # calculate 3^(3+1) - 3*3 = 81 - 9 = 72 = "H" 
  .O.?+))     # calculate 72 + 3^3 + 1 + 1 = 72 + 27 + 2 = 101 = "e"
  .O.*+((     # calculate 101 + 3*3 - 1 - 1 = 101 + 9 - 2 = 108 = "l"
  .           # ...and duplicate it for another "l"
  .O+         # calculate 108 + 3 = 111 = "o"
  .           # ...and duplicate it for later use
  O(.O+?      # calculate (3-1)^(3-1+3) = 2^5 = 32 = " "
  .O-O*       # calculate (32 - 3) * 3 = 29 * 3 = 87 = "W"
  @           # pull the second 111 = "o" to the top of the stack
  .O+         # calculate 111 + 3 = 114 = "r"
  O.+$        # copy the (3+3 = 6)th last element on the stack, 108 = "l", to top
  .O.*-)      # calculate 108 - (3*3) + 1 = 108 - 9 + 1 = 100 = "d"
  .O/         # calculate int(100 / 3) = 33 = "!"
]             # collect everything after the [ into an array
+             # stringify the array by appending it to the input string
share|improve this answer

I believe, Brainfuck is the best tool for this puzzle:

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

code length: 111

Algorithm explained

Increment cell 0 to 10 (it will be loop counter)
Repeat 10 times ; will stop at cell 0
  Increment cell 1 to 7
  Increment cell 2 to 10
  Increment cell 3 to 3
  Increment cell 4 to 1
Increment cell 1 by 2 and output it ; Thus, output ASCII 72 'H'
etc. for all symbols in 'Hello World!'

Longer version without loop:

+++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++.+++++++++++++++++
++++++++++++.+++++++..+++.-------------------
---------------------------------------------
---------------.+++++++++++++++++++++++++++++
++++++++++++++++++++++++++.++++++++++++++++++
++++++.+++.------.--------.------------------
---------------------------------------------
----.-----------------------.

code length: 389

share|improve this answer
This is a code-golf puzzle, the point is to make the shortest possible program. Part of that involves posting the length of your code. – zzzzBov Mar 18 '12 at 19:44
Thanks for the point. Fixed – Michael Mar 19 '12 at 3:20

Deadfish - 282 Characters

iiisdsiiiiiiiioiiiiiiiiiiiiiiiiiiiiiiiiiiiiioiiiiiiiooiiiodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddodddddddddddddddddddddddsiiiiiioiiiiiiiiiiiiiiiiiiiiiiiioiiioddddddoddddddddodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddo

Yes, this was hand-coded (machine-tested, though). I am also pretty sure that this is the shortest possible length.

Deadfish has four instructions:

  1. i increments the accumulator.

  2. d decrements the accumulator.

  3. s multiplies the accumulator by itself.

  4. o outputs the accumulator as an ASCII character.

There is neither input nor control flow nor the ability to reset the accumulator.

share|improve this answer

C, 327 chars

#define O(O)-~O
#define OO(o)O(O(o))
#define Oo(o)OO(OO(o))
#define oO(o)Oo(Oo(o))
#define oo(o)oO(oO(o))
#define O0 putchar
main() {
    O0(OO(oO(!O0(~O(Oo(OO(-O0(~O(Oo(-O0(O(OO(O0(oo(oO(O0(O(oo(oO(OO(Oo(oo(oO(
    O0(oo(oo(!O0(O(OO(O0(O0(O(OO(Oo(O0(O(Oo(oo(oO(O0(oo(oo(oO(oo(oo(0))))))))
    ))))))))))))))))))))))))))))))))))))));
}

Strangely, it does't lose its beauty after preprocessing:

main() {
putchar(-~-~-~-~-~-~-~-~-~-~!putchar(~-~-~-~-~-~-~-~-putchar(~-~-~-~-~-~-
putchar(-~-~-~putchar(-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~putchar(
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~putchar(-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
-~-~-~-~-~-~-~-~-~-~-~-~-~!putchar(-~-~-~putchar(putchar(-~-~-~-~-~-~-~putchar
(-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~putchar(-~-~-~-~-~-
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~0))))))))))));
}
share|improve this answer

Python 272 chars

s=ord('O')
a=len('0')
b=a+a
c=b+a
d=c+a
e=d+a
f=e+a
g=f+a
h=g+a
print chr(s-g)+chr(s+g*c+a)+chr(s+g*d+a)+chr(s+g*d+a)+chr(s+h*d)+chr(s-h*f+a)+chr(s+h)+chr(s+h*d)+chr(s+g*e)+chr(s+g*d+a)+chr(s+g*c)+chr(s-h*f+b)

Though I'm surprised no one tried this method

Python 31 chars

f=open(r'/0.O',)
print f.read()
share|improve this answer

PHP – 49 chars

<?=Hello.chr(($a=-~-~-~0).~-$a).World.chr($a.$a);

Changelog:

  • (73 -> 86) Forgot to output an exclamation point... sigh
  • (86 -> 57) Uses a single variable with incrementing
  • (57 -> 51) Changed to use bitwise operators on 0
  • (51 -> 49) More bitwise operators
share|improve this answer
Pretty sure that the constants would count as string literals because of the conversions. – Kevin Brown Mar 13 '11 at 18:23
@Bass5098 Thanks for your edit! I approved it. – nyuszika7h Mar 13 '11 at 18:34
@Bass5098 that doesn't work, you need to have chars 32 and 33, not 21 and 22. <?$a=-~-~-~0;echo Hello.chr($a.$a-1).World.chr($a.$a); works, but it's 54 chars. – zzzzBov Mar 16 '11 at 18:07
@zzzzBov I could not figure out how to clear the edit initially, and forgot to roll it back once it was approved. – Kevin Brown Mar 16 '11 at 22:52
whoops, i left the 1 in there. There I go breaking my own rules...<?$a=-~-~-~0;echo Hello,chr($a.~-$a),World,chr($a.$a); is what I should have used, still 54 chars. – zzzzBov Mar 16 '11 at 23:34
show 1 more comment

Heres my Perl entry.

It uses the length of an array to store the ordinal of the character.

use strict;
use warnings;
use 5.010;
my @hello_world = (
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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
say map{ chr @$_ } @hello_world;

That seemed like a lot of writing to me, so I used this to generate the above code:

perl -E'
  say for map{"use $_;"} qw"strict warnings 5.010";
  say "my \@hello_world = (";
  say "  [",join(",",@$_),"]," for map{[(0) x ord]} split //, "Hello World";
  say ");";
  say q"say map{ chr @$_ } @hello_world;"
'
share|improve this answer

J, 250

oo=:#a.
o0=:<.o.^0
o0o=:%:%:%:oo
ooo=:p:^:(-*oo)
o=:<.(^^^0)*(^^0)*(^^0)
o00=:o,~(,[)o0(**(**[))o0o
oo0=:*/p:(!0),>:p:!0
echo u:(o0(**(**]))o0o),(ooo ooo ooo(o.o.^^^0)*oo),o00,(+:%:oo),(oo0-~!p:>:>:0),o,(<.-:o.o.^o.^0),(>:p:(]^])#o00),(*:#0,#:oo),oo0

I had entirely too much fun with this one, and I learned a little bit more J to boot. Also, ooo ooo ooo may be the stupidest code I've ever written.

share|improve this answer

Python (169) -- FIXED

Quite a bit longer than the other solutions. But more insane.

from turtle import setworldcoordinates as w
o=0**0
t=o+o+o
b=cmp.__ne__.__doc__
print(hex.__name__[0]+str(Ellipsis)[:t]+"O"+b[-t*t-o]+w.func_name[t:t*t-o]+b[-t]).title()
share|improve this answer
Sorry, typo on my behalf. I've corrected that error now. – Jagu Mar 19 '11 at 0:35
Nice. I would retract my downvote, but this stupid website doesn’t let me, so don’t blame me... – Timwi Mar 19 '11 at 17:00
@Timwi: I think if a question/answer is edited, you can undo your vote, can't you? – nyuszika7h Apr 27 '11 at 5:18
@Nyuszika7H: Yes, but if the makers of the website are so dumb and obstinate that they won’t remove this braindread limitation, I’m not going to jump through hoops and make pointless edits. Besides, most people can’t even make pointless edits. – Timwi Apr 28 '11 at 13:36

Mathematica 12 chars

Only symbols, no strings.

Hello World!   

The ! is a factorial operator, but as the symbols Hello and World are undefined, returns the input unchanged.

If we modify the program a bit:

Hello=2;
World=3;
Hello World!  

Then it prints 12 (2 * 3!)

share|improve this answer
1 2

Your Answer

 
discard

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

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