47
\$\begingroup\$

Your goal is to write "Hello, World!" (minus the quotes). This is a , so most up votes wins. Code length will be used to break ties.
Anything goes, as long as it is within the following rules:

  • All characters must be either letters or numbers, so you may only use characters in the string "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".
  • All code you use must be in one file, with the exception of imported modules/classes/whatever they're called in your favourite language.
  • Only the standard libraries/frameworks for your language of choice are allowed (for example, Python's Math module is allowed, but Numpy, Scipy, and Pygame are not). I will allow TkInter as it is the de facto standard for GUIs in Python.
  • No input is permitted, be it reading from stdin, reading a file, displying an image, or reading from the web.

+10 brownie points if you figure out how to do it in Java without bending the rules.


On your marks, get set, code!

EDIT: braces ({}), brackets ([]), and parentheses (()) are allowed as this would be pretty much impossible for most languages without them. I'm also removing the character limit rule. Hopefully this will make it more interesting.

EDIT^2: white space is also allowed. My brain isn't working properly, sorry. >.<

\$\endgroup\$
18
  • 1
    \$\begingroup\$ Up to you, I'm just making sure. What about whitespace? \$\endgroup\$
    – Geobits
    Mar 5, 2014 at 14:04
  • 1
    \$\begingroup\$ Oh, right white space. My brain is clearly not functioning properly today. That should be allowed. One second, let me fix the rules. \$\endgroup\$
    – wec
    Mar 5, 2014 at 14:15
  • 9
    \$\begingroup\$ So, no operators? And, most importantly, no ;? How can I write anything in C? \$\endgroup\$
    – Oberon
    Mar 5, 2014 at 14:22
  • 1
    \$\begingroup\$ esolangs.org Hello, World! \$\endgroup\$
    – Geobits
    Mar 5, 2014 at 22:41
  • 3
    \$\begingroup\$ +1 for figuring out how to exclude J in a natural way: 72 101 108 108 111 44 32 87 111 114 108 100 33{a. requires the period at the end to work, and a path through u: similarly requires a colon. Without . and : we are nothing. \$\endgroup\$ Mar 5, 2014 at 23:32

52 Answers 52

1
2
4
\$\begingroup\$

J - 73 char

It can be done, after all!

72 101 108 108 111 44 32 87 111 114 108 100 33{do 1 8{show 0 def 0
take
)

Here's the thing about J. Most of the primitives are ASCII punctuation, followed by up to two dots or colons. Those primitives that aren't made of punctuation are an alphanumeric character followed up to two dots or colons. So we're allowed none of those, except for { } [ ]. [ and ] are identity verbs and are thus useless.

Luckily, { indexes arrays, so if we had, say, a string with every single ASCII character (a., called Alphabet), we could pull the letters out by their ASCII codepoints. We also have a backup way of making strings, 0 : 0 and then stuff and then a lone ); the colon in which has an alias in the standard library, def.

Then there's a verb in the standard library, show, that gives you the internal representation of a verb if you pass it the name as a string. There's another verb, do, that will eval a string. So if we can pull out an a. from any such representation, we can eval that and pull out Hello, World!.

Our saviour comes in the form of take, an alias for {. that has an a in its name. show'take' will return take=: {., so we have our a. and thus a solution.

We can get rid of { by using the essentially equivalent pick from the standard library, but the paren at the very end can't be avoided.

\$\endgroup\$
4
\$\begingroup\$

perl

How about a more straight-forward perl implentation?

print q zHelloz and print chr 44 and print q z worldz and print chr 33
\$\endgroup\$
4
\$\begingroup\$

GolfScript

389960998265612367812323333 115base]zip

Try it online.

How it works

Since both number and square brackets are allowed, pushing an array containing the character codes of all bytes in the string “Hello, World!” is straightforward:

[72 101 108 108 111 44 32 87 111 114 108 100 33]

The highest character count is 114, so we could also push this array as a base 115 number:

389960998265612367812323333 115base

The problem lays in casting this array to a string. There's already a string on the stack (the empty string, since there was no input from STDIN). Strings have higher priority than arrays in GolfScript, so any way of combining the empty string with the array from above will yield a string.

Almost all built-ins are out, since they use non-alphanumeric characters (e.g., + for concatenation), but we can use zip, which transposes array rows with columns.

First, we append a ] to the array, so a two-dimensional array consisting of the empty string an the character array will lay on the stack.

Then, we append zip. The result of the transpose will be the following array:

[   "H"   "e"   "l"   "l"   "o"   ","   " "   "W"   "o"   "r"   "l"   "d"   "!"   ]

By default, GolfScript prints all item on the stack, one by one. The result is:

Hello, World!
\$\endgroup\$
3
\$\begingroup\$

GO (golang)

package main

func main() {
    print(string(72))
    print(string(101))
    print(string(108))
    print(string(108))
    print(string(111))
    print(string(44))
    print(string(32))
    print(string(87))
    print(string(111))
    print(string(114))
    print(string(108))
    print(string(100))
    print(string(33))
}

No "fmt" used... Just print.

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

Lua (112)

io[ [[write]]][[Hello]]io[ [[write]]](string[ [[char]]](44))io[ [[write]]][[ World]]print(string[ [[char]]](33))

Pretty straightforward. Lua's alternate string syntax is quite a boon here, in addition to "the only data structure is a table" which means that io.write is equilavent to io['write'].

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

Haskell

Not exactly a program, as it is impossible to create a program without main=. This is simply an expression for an interactive interpreter, such as ghci:

putStrLn (map toEnum (scanl (const id) 72 (scanl (const id) 101 (scanl (const id) 108 (scanl (const id) 111 (scanl (const id) 44 (scanl (const id) 32 (scanl (const id) 119 (scanl (const id) 111 (scanl (const id) 114 (scanl (const id) 108 (scanl (const id) 100 [33]))))))))))))

scanl (const id) is used instead of (:),
toEnum :: a -> Char is used instead of chr, as I'd have to import Data.Char then.

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

Emacs Lisp

Displays "Hello, World!" in a browser when you eval it.

it's lisp as ascii values of base64 of lisp of base64 of ascii values if you start unobfuscating it.

(eval (read (eval (list (intern (string 98 97 115 101 54 52 45 100 101 99 111 100 101 45 115 116 114 105 110 103))
                        (string 75 71 120 108 100 67 65 111 75 71 90 112 98 71 85 103 75 71 86 50 89 87 119 103
                                75 72 74 108 89 87 81 103 75 71 74 104 99 50 85 50 78 67 49 107 90 87 78 118 90
                                71 85 116 99 51 82 121 97 87 53 110 73 67 74 76 83 69 52 119 89 50 49 115 100 86
                                112 53 10 81 84 86 78 97 85 70 52 84 85 82 82 90 48 49 85 81 88 104 74 82 69 86
                                51 84 48 78 66 101 69 49 69 90 50 100 78 86 69 86 52 83 85 82 70 101 69 57 84 81
                                88 104 78 86 69 86 110 84 86 82 70 77 69 108 69 82 88 100 80 81 48 70 52 84 85 82
                                66 10 90 48 49 85 82 88 104 74 82 69 86 52 84 110 108 66 101 69 49 85 87 87 100
                                78 86 69 86 53 83 85 82 70 101 69 53 53 81 88 104 78 86 70 108 110 84 107 82 90
                                90 48 49 85 81 84 66 74 82 69 86 52 84 109 108 66 101 69 49 69 97 50 100 78 86 69
                                69 48 10 83 49 69 57 80 83 73 112 75 83 107 112 75 83 65 111 100 50 108 48 97 67
                                49 48 90 87 49 119 76 87 90 112 98 71 85 103 90 109 108 115 90 83 65 111 97 87 53
                                122 90 88 74 48 73 67 104 108 100 109 70 115 73 67 104 121 90 87 70 107 73 67 104
                                105 89 88 78 108 10 78 106 81 116 90 71 86 106 98 50 82 108 76 88 78 48 99 109 108
                                117 90 121 65 105 83 48 104 79 77 71 78 116 98 72 86 97 101 85 69 121 84 85 78 66
                                101 69 49 69 85 87 100 79 86 69 86 110 84 109 112 74 90 48 53 54 83 87 100 78 86 69
                                70 52 83 85 82 70 10 100 48 57 68 81 88 104 78 82 71 100 110 84 86 82 70 101 69 108
                                69 85 84 66 74 82 69 49 53 83 85 82 110 77 48 108 69 82 88 104 78 85 48 70 52 84 86
                                82 82 90 48 49 85 81 84 82 74 82 69 86 51 84 85 78 66 101 107 49 53 81 84 74 78 81
                                48 69 119 10 84 110 108 66 101 69 49 69 85 87 100 79 86 69 86 110 84 109 112 74 99
                                67 73 112 75 83 107 112 75 83 65 111 89 110 74 118 100 51 78 108 76 88 86 121 98 67
                                49 118 90 105 49 109 97 87 120 108 73 71 90 112 98 71 85 112 73 67 107 103)))))

enter image description here

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

CJam

One of the few answers satisfying the original requirement for the character set:

72c101c108c108c111c44c32c87c111c114c108c100c33c

This straightforwardly builds the string character by character.

Another solution:

389960998265612367812323333 115b{Xc}fX

This converts the first number to base 115 then converts each digit to a character.

And finally, a solution that uses only 3 different characters: K, ) and c (newlines are optional):

K))))))))))))))))))))))))))))))))))))))))))))))))))))c
K)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))c
K))))))))))))c
K)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))c
K)))))))))))))c

I used K because it's the variable initialized with the largest number (20).

Online interpreter: http://cjam.aditsu.net/

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

FORTH

UPDATE: Here's the basically similar version that executed straight from forth file, as opposed to defining a WORD (subroutine) and it uses only alphanumeric characters.

72 EMIT
101 EMIT
108 EMIT
108 EMIT
111 EMIT
44 EMIT
32 EMIT
87 EMIT
111 EMIT
114 EMIT
108 EMIT
100 EMIT
33 EMIT

been a while with FORTH but this seems to work, thanks for the 'C' language reply I didn't bother looking up ACSII codes. I used the iMop and iBucket (http://sourceforge.net/projects/powermops/files/iMops/) and also tested with an osx variant (https://sites.google.com/site/chrishinsley/)

: HELLOWORLD ( -- )
72 EMIT
101 EMIT
108 EMIT
108 EMIT
111 EMIT
44 EMIT
32 EMIT
87 EMIT
111 EMIT
114 EMIT
108 EMIT
100 EMIT
33 EMIT
;

code: 224 data: 16

cr HELLOWORLD

Hello, World!

\$\endgroup\$
3
  • \$\begingroup\$ I don't think :, -, or ; are allowed. Otherwise, nice post. \$\endgroup\$
    – user10766
    Mar 8, 2014 at 1:29
  • \$\begingroup\$ the colon, dash, and semi-colon are language basic delimiters. although there might be some way to type it in the interpreter without defining a WORD (which is Forth for subroutine). maybe I'll try APL next. :-0 \$\endgroup\$
    – labiche
    Mar 8, 2014 at 2:57
  • \$\begingroup\$ Yeah, I know. This challenge is a tough one to start on. \$\endgroup\$
    – user10766
    Mar 8, 2014 at 2:59
1
\$\begingroup\$

Python, 148 bytes

from binascii import unhexlify
print unhexlify(bytearray(str(0)if c in hex(14)else c for c in hex(0x48656c6c6f2c2e776f726c6421)if c not in hex(0L)))
\$\endgroup\$
1
\$\begingroup\$

REXX

Using standard build-in functions only (ASCII based)

  SAY x2c(48656c6c6f2c20576f726c6421)

Yields:

Hello, World!

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

PHP - 46 bytes (with invalid underscore)

if(print(base64_decode(SGVsbG8sIFdvcmxkIQ))){}

PHP - 88 bytes

if(print(Hello))if(print(chr(44)))if(print(chr(32)))if(print(World))if(print(chr(33))){}

Works by abusing the fact that PHP will assume any unassigned constant is a string equal to its name.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Underscore is not allowed \$\endgroup\$
    – Sylwester
    May 13, 2014 at 11:37
  • \$\begingroup\$ So second nature I hadn't even realised. Luckily, I had an alternate. \$\endgroup\$
    – Eligos
    May 13, 2014 at 15:17
1
\$\begingroup\$

Racket

(quasiquote (unquote (quote (Hello (unquote (quote World))))))

It barely works. The output is '(Hello ,'world)

To run this code, start DrRacket and paste the code above to the console.

Don't do it in Advanced Student Language, it shows up (list 'Hello (list 'unquote (list 'quote 'world))) instead.

\$\endgroup\$
0
\$\begingroup\$

JavaScript:

with(String) {
    with(console) {
        log(fromCharCode(72))
        log(fromCharCode(101))
        log(fromCharCode(108))
        log(fromCharCode(108))
        log(fromCharCode(111))
        log(fromCharCode(44))
        log(fromCharCode(32))
        log(fromCharCode(87))
        log(fromCharCode(111))
        log(fromCharCode(114))
        log(fromCharCode(108))
        log(fromCharCode(100))
        log(fromCharCode(33))
    }
}

Unfortunately the Firefox console displays this as

H
e
l(2)
o

etc....

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

VBA

Since equals, quotes and dot are out of the question, and as everyone loves message boxes:

Sub helloworld()
    MsgBox Chr(72)
    MsgBox Chr(101)
    MsgBox Chr(108)
    MsgBox Chr(108)
    MsgBox Chr(111)
    MsgBox Chr(44)
    MsgBox Chr(87)
    MsgBox Chr(111)
    MsgBox Chr(114)
    MsgBox Chr(108)
    MsgBox Chr(100)
    MsgBox Chr(33)
End Sub
\$\endgroup\$
0
\$\begingroup\$

Lua

io[ [[write]]][[Hello]]
io[ [[write]]](string[ [[char]]](44))
io[ [[write]]][[ World]]
io[ [[write]]](string[ [[char]]](33))

edit: Didn't see AlliedEnvy's answer, which is identical to mine, except mine doesn't print a newline at the end.

\$\endgroup\$
0
\$\begingroup\$

PHP (111 chars)

<?=chr(72).chr(101).chr(108).chr(108).chr(111).chr(44).chr(32).chr(87).chr(111).chr(114).chr(108).chr(100).chr(33)?>

Assuming . is OK (I have used: [chr0-9\(\)\.]).

\$\endgroup\$
0
\$\begingroup\$

dc - 25 bytes

33[ World]44[Hello]PaPPap

I'm starting to like dc.

\$\endgroup\$
0
\$\begingroup\$

Logo, 52 chars

pr se word [Hello] char 44 word char [World] char 33

Using the new rule that brackets are allowed. Otherwise, one could word together lots more chars to achieve the same goal.

\$\endgroup\$
0
\$\begingroup\$

Julia

Option 1, using square brackets and join, and just one print/char:

print(join(char([72 101 108 108 111 44 32 87 111 114 108 100 33])))

Option 2, one "char" at a time:

print(char(72))
print(char(101))
print(char(108))
print(char(108)
print(char(111))
print(char(44))
print(char(32))
print(char(87))
print(char(111))
print(char(114))
print(char(108))
print(char(100))
print(char(33))

Options 3 + 4, same as above, but with 0x?? char creation. That is, rather than char(72), use 0x72. Or, in the join case, replace 72 with 0x72 (and so on) and remove the "char" operation entirely.

\$\endgroup\$
0
\$\begingroup\$

Java (NetBeans)

class Hello extends Exception
{
    Hello(String s)
    {
        super(s)
    }
}

public class HelloWorld
{
    public static void main(String[] args) throws Hello
    {
        world((char)130)
    }
    
    static void world(char c) throws Hello
    {
        throw new Hello(new String(new char[]{c}))
    }
}

Output:

Exception in thread "main" Hello: ,
    at HelloWorld.world(HelloWorld.java:18)
    at HelloWorld.main(HelloWorld.java:13)
Java Result: 1

A few notes:

  1. NetBeans allows you to omit semicolons, but isn't happy about it. Eclipse and javac don't compile.
  2. I don't get the +10 brownie points, since including unnecessary output is bending (but not violating) the rules.
  3. The exclamation point is courtesy of NetBeans, objecting like crazy to the lack of semicolons.
\$\endgroup\$
4
  • 1
    \$\begingroup\$ I get Hello.java:12: error: ';' expected super(s) from the compiler. \$\endgroup\$
    – Riking
    Mar 6, 2014 at 20:27
  • \$\begingroup\$ @Riking What IDE are you using? \$\endgroup\$
    – Ypnypn
    Mar 6, 2014 at 20:30
  • \$\begingroup\$ That was with javac. Eclipse gives Exception in thread "main" java.lang.Error: Unresolved compilation problem: Syntax error, insert ";" to complete BlockStatements when you try to run it. \$\endgroup\$
    – Riking
    Mar 6, 2014 at 20:50
  • \$\begingroup\$ Okay; I guess it's compiler-dependent. \$\endgroup\$
    – Ypnypn
    Mar 6, 2014 at 20:54
-2
\$\begingroup\$

Common Lisp

This almost works, except that - isn't allowed. If only there were the functions stringCapitalize and codeChar instead…

(mapcar (lambda (x)
          (princ (string-capitalize x)))
        (list (quote hello)
              (code-char 44)
              (code-char 32)
              (quote world)
              (code-char 33))))

The nice thing here is that string-capitalize takes a string designator, which can be a string, symbol, or character. Sample use:

CL-USER> (mapcar (lambda (x)
                   (princ (string-capitalize x)))
                 (list (quote hello)
                       (code-char 44)
                       (code-char 32)
                       (quote world)
                       (code-char 33)))
Hello, World!
\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately, - is banned. \$\endgroup\$
    – Geobits
    Mar 5, 2014 at 18:59
  • \$\begingroup\$ @Geobits aww… I got excited when I saw that parens were allowed… I think I can work around this, though \$\endgroup\$ Mar 5, 2014 at 18:59
1
2

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