523
\$\begingroup\$

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with , and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.

Furthermore, while all of Wikipedia (the Wikipedia entry has been deleted but there is a copy at archive.org ), esolangs and Rosetta Code have lists of "Hello, World!" programs, none of these are interested in having the shortest for each language (there is also this GitHub repository). If we want to be a significant site in the code golf community, I think we should try and create the ultimate catalogue of shortest "Hello, World!" programs (similar to how our basic quine challenge contains some of the shortest known quines in various languages). So let's do this!

The Rules

  • Each submission must be a full program.

  • The program must take no input, and print Hello, World! to STDOUT (this exact byte stream, including capitalization and punctuation) plus an optional trailing newline, and nothing else.

  • The program must not write anything to STDERR.

  • If anyone wants to abuse this by creating a language where the empty program prints Hello, World!, then congrats, they just paved the way for a very boring answer.

    Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

  • Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

  • This is not about finding the language with the shortest "Hello, World!" program. This is about finding the shortest "Hello, World!" program in every language. Therefore, I will not mark any answer as "accepted".

  • If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf - these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

For inspiration, check the Hello World Collection.

The Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](https://esolangs.org/wiki/Fish), 121 bytes

/* Configuration */

var QUESTION_ID = 55422; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8478; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = (function(){
  var headerTag     = String.raw `h\d`
  var score         = String.raw `\-?\d+\.?\d*` // with negative/floating-point support
  var normalText    = String.raw `[^\n<>]*` // no HTML tag, no newline
  var strikethrough = String.raw `<s>${normalText}</s>|<strike>${normalText}</strike>|<del>${normalText}</del>`
  var noDigitText   = String.raw `[^\n\d<>]*`
  var htmlTag       = String.raw `<[^\n<>]+>`

  return new RegExp(
  String.raw  `<${headerTag}>`+
  String.raw    `\s*([^\n,]*[^\s,]),.*?`+
  String.raw    `(${score})`+
  String.raw    `(?=`+
  String.raw      `${noDigitText}`+
  String.raw      `(?:(?:${strikethrough}|${htmlTag})${noDigitText})*`+
  String.raw      `</${headerTag}>`+
  String.raw    `)`
  );
})();

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    lang = jQuery('<i>' + a.language + '</i>').text().toLowerCase();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.uniq > b.uniq) return 1;
    if (a.uniq < b.uniq) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  float: left;
}

#language-list {
  padding: 10px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654">
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>

<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
22
  • 4
    \$\begingroup\$ @isaacg No it doesn't. I think there would be some interesting languages where it's not obvious whether primality testing is possible. \$\endgroup\$ Commented Aug 28, 2015 at 13:56
  • 7
    \$\begingroup\$ If the same program, such as "Hello, World!", is the shortest in many different and unrelated languages, should it be posted separately? \$\endgroup\$ Commented Aug 28, 2015 at 15:33
  • 2
    \$\begingroup\$ @mbomb007 Well it's hidden by default because the three code blocks take up a lot of space. I could minify them so that they are a single line each, but I'd rather keep the code maintainable in case bugs come up. \$\endgroup\$ Commented Aug 28, 2015 at 19:34
  • 8
    \$\begingroup\$ @ETHproductions "Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge." Publishing the language and an implementation before posting it would definitely be helpful though. \$\endgroup\$ Commented Aug 29, 2015 at 23:01
  • 2
    \$\begingroup\$ @MartinEnder ... Almost. If two BF solutions have the same size, the one with smaller lexicographical order will take smaller number of bytes in Unary. Of course the smallest Unary solution translated to BF is guaranteed to be smallest. \$\endgroup\$
    – user202729
    Commented May 20, 2018 at 10:20

1002 Answers 1002

1 2
3
4 5
34
15
\$\begingroup\$

Wierd, 1341 bytes

Unlike other languages where the symbols in a program determine which instructions are executed, in Wierd, it is the bends in the chain of arbitrary symbols that determine which instructions are executed.

From the website:

First, a Riddle:
Q: What do you get when you put three marginally-sane programmers on a mailing list with the Befunge and BrainF*** programming languages?
A: You get BeF***, and then they get Wierd.
...
Chris Pressey then jumped on it, created the angle-to-instruction mapping, and christened the entire mess "Wierd"--a cross between the words "weird" (which the language seemed to be) and "wired" (which would describe the appearance of programs written in the language).

Try it online at http://catseye.tc/installation/Wierd_(John_Colagioia)

EDIT: Dennis has killed this answer quite thoroughly with this

Even though this is much smaller than the sameple that comes with the interpreter I am positive this can be golfed more (and it has been - by Dennis) Please try to come up with something smaller and edit the question with that version.

,!dlroW             ++
o     #           ++  +
l               ++    + ++++
l     +++     ++      ++  +
e    +   +  ++    ++  +  +
H   +  +  ++    ++  +   +
+  +  ++      ++     +++
+ ++++ +    ++
+      +  ++           ++
+  +++++++   +++     ++  +
 ++    +    +   +  ++    + ++++
       +   +  +  ++      ++  +
       +  +  ++      ++  +  +
       + ++++ +    ++  +   +
       +      +  ++     +++
       +  +++++++
        ++    +   +++
    +         +  +   +  ++
    ++       +  +  +  ++  +
    + +     +  +  ++      + ++++
    +  +    + ++++ +      ++  +
     +  +   +      +  ++  +  +
      +  +  +  +++++++  +   +
    ++++  +  ++    +     +++
    +      +       +
     +      +++++++      +++
      +                ++   +
       +             ++     +
       +           ++      +
++++++++++++     ++   ++  ++++
 +     +    +  ++   ++  +     +
  ++++ +     ++   ++     +++++++
    +  +        ++
   +   +      ++
  +    +    ++
 +     +  ++
+       ++        +++
+               ++   +
+ +++++++     ++     +
+  +     +  ++      +
+   ++++  ++   ++  ++++
+     +      ++  +     +
+    +     ++     +++++++
+    +   ++
+  ++++++   +++++++     +++
 ++  +       +     +  ++   +
     +        ++++  ++     +
     +          +         +
     +      ++++     ++  ++++
     +             ++  +     +
     +  +++++++++++     +++++++
      ++
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice job! I was hoping someone would beat the official HW example eventually. :) \$\endgroup\$ Commented Jan 12, 2016 at 9:15
  • \$\begingroup\$ I wonder if they misspelled "weird" intentionally... \$\endgroup\$
    – mbomb007
    Commented Feb 24, 2016 at 19:58
  • 1
    \$\begingroup\$ @mbomb007 Yes. The web page catseye.tc/view/wierd/dialect/wierd-jnc/doc/wierdspec.txt says that Chris Pressey then jumped on it, created the angle-to-instruction mapping, and christened the entire mess "Wierd"--a cross between the words "weird" (which the language seemed to be) and "wired" (which would describe the appearance of programs written in the language) \$\endgroup\$ Commented Feb 24, 2016 at 20:12
14
\$\begingroup\$

Fortran, 28 bytes

print'("Hello, World!")'
end

You can't write print*,"Hello, World!" because there's a leading space in the default print format. Thus, we pass in our own format that simply contains a constant string.

\$\endgroup\$
4
  • \$\begingroup\$ Which version of Fortran is this? In F77 you'd need some spacing if I'm not mistaken. \$\endgroup\$ Commented Jul 19, 2016 at 12:37
  • \$\begingroup\$ @RobertBenson F77 would also require fixed form if I'm not mistaken. In any case, this works in GFortran. tio.run/##S8svKilKzNNNT4Mw/v8vKMrMK1HXUPJIzcnJ11EIzy/… \$\endgroup\$
    – Dennis
    Commented Jun 6, 2017 at 6:24
  • \$\begingroup\$ Yes, F77 is fixed format, so you'd need some tabs, which adds to byte-count :( \$\endgroup\$ Commented Jun 7, 2017 at 15:10
  • 1
    \$\begingroup\$ GFortran: print*,"Hello, World!";end 26 bytes, but it prefixes a space char :( \$\endgroup\$
    – roblogic
    Commented Aug 27, 2019 at 9:55
14
\$\begingroup\$

C#, 85 67 bytes

class P{static void Main(){System.Console.Write("Hello, World!");}}

I guess it cannot get worse. Did not even beat Java this time.

\$\endgroup\$
4
  • 7
    \$\begingroup\$ class P{static void Main(){System.Console.WriteLine("Hello, World!");}} -- 71 bytes. More golfing you must do young padawan. \$\endgroup\$ Commented Aug 28, 2015 at 13:36
  • 7
    \$\begingroup\$ You don't need to specify the accessibility modifiers, C# will use defaults so you can remove both instances of public . You can also use the Write method on Console to save a few more bytes. \$\endgroup\$
    – user20151
    Commented Aug 28, 2015 at 13:36
  • 4
    \$\begingroup\$ The newline in the output is optional, so use Write instead of WriteLine to save 4 bytes \$\endgroup\$
    – SLuck49
    Commented Aug 28, 2015 at 15:49
  • \$\begingroup\$ Yeah, a lang of Microsoft is worse than Java! \$\endgroup\$
    – univalence
    Commented Jul 18, 2016 at 18:23
14
\$\begingroup\$

Hexagony, 30 29 bytes

H;_e;r;2l.;P.QW;l/P1;@;0d;\o;

Try it online!

Source laid out:

    H ; _ e
   ; r ; 2 l
  . ; P . Q W
 ; l / P 1 ; @
  ; 0 d ; \ o
   ; . . . .
    . . . .

One more byte off!

Here's a crappy gif of the program in action.

29 byte gif

Given there's 2 nops inside the program itself, I'm confidant this can be golfed by at least one more byte. I'm willing to offer a bounty for a smaller version.

Old version:

H;e;r;0Pld;P_1;l;;o;Q\;W\;$2@\

Try it online!

Source laid out:

    H ; e ;
   r ; 0 P l
  d ; P _ 1 ;
 l ; ; o ; Q \
  ; W \ ; $ 2
   @ \ . . .
    . . . .

Reuses the same tricks as Martin Ender's answer, i.e Q2 printed is the comma, P0 is the space, P1 is the bang, but manages to be 2 bytes shorter through clever mirroring to reuse several ;s and the o.

Explanation:

Here's a coloured Hexagony grid to show the non-branching path that the pointer takes:

30 byte path

The executing code, ignoring mirrors, is:

H;e;l;;o;Q2;P0;W;d$;o;$2r;0Pl;Wd;P1;@

Filtering out the skipped instructions and the literals that are overwritten by other literals, we are left with:

H;e;l;;o;Q2;P0;W;o;r;l;d;P1;@

Which simply prints "Hello, World!"

After a few attempts, I gave up on a size 3 Hexagony answer. You need a minimum of 12 instructions out of 19 reserved for string literals, along with three ;s for printing and one @ for ending the program. This leaves only 3 spaces for IP management and memory management, provided you find the optimal path that reuses both the o and the l. From all this, I'll rule that a size 3 answer is impossible, though I'll give a sizable bounty to anyone who proves me wrong.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I posted a shorter solution. \$\endgroup\$
    – user202729
    Commented May 19, 2018 at 13:55
  • 1
    \$\begingroup\$ I came up with a 25-byte solution by hand - this will be my first answer here! I'm a bit miffed now to find this has already been beaten, albeit by brute force. Up until half an hour ago i thought Martin's original post was the only one for Hexagony. Still, my approach is different from the others. Hope to post soon although it may have to wait till Saturday when I get back from vacation and have access to my computer again. \$\endgroup\$
    – Oliphaunt
    Commented Aug 22, 2018 at 20:29
  • \$\begingroup\$ @Oliphaunt It's been a while, but I noticed you never posted your 25 byte solution. Do you still have it or remember it? \$\endgroup\$
    – Jo King
    Commented Sep 26, 2019 at 2:51
14
\$\begingroup\$

Z80Golf, 19 bytes

00000000: 674a 4343 4003 0f78 405d 434b 0e76 7e23  [email protected]@]CK.v~#
00000010: e5ee 2f                                  ../

Try it online!

Z80Golf is, essentially, a Z80 machine hooked up to $8000=putchar and $8003=getchar. The source code is a binary copied to $0000 (all other memory is zeroed out, just like the registers); execution starts there and runs until a halt instruction.

It was designed by mokehehe on anarchy golf for code golf competitions there, but seems to have fallen into disuse. It's really fun to golf in, but excelling in it requires a pretty thorough understanding of the Z80 chip (that I myself don't even have, but some golfers like kodera and *yuko* do, and every solution they write is very clever.)

A naïve Hello, World! program might look like this:

start:
  ld a, (ix+hello)
  or a
  jr nz, okay
  halt
okay:
  call $8000  ; putchar
  inc ix
  jr start
hello:
  db "Hello, World!"

It assembles into a 27 byte binary. It even cheats a little bit: we don't need to explicitly zero-terminate the string "Hello, World!" ourselves, as all the memory past our source code is zeroed already. And it's still a fair bit longer than our 19-byte solution.

So how does the 19-byte solution work?

It doesn't look much like a Hello, World! program when disassembled:

  ld h,a
  ld c,d
  ld b,e
  ld b,e
  ld b,b
  inc bc
  rrca
  ld a,b
  ld b,b
  ld e,l
  ld b,e
  ld c,e
  ld c,0x76
  ld a,(hl)
  inc hl
  push hl
  xor 0x2f

We can look at the program in a slightly more revealing manner.

  db 47 ^ 'H'  ; 67  ld h, a
  db 47 ^ 'e'  ; 4a  ld c, d
  db 47 ^ 'l'  ; 43  ld b, e
  db 47 ^ 'l'  ; 43  ld b, e
  db 47 ^ 'o'  ; 40  ld b, b
  db 47 ^ ','  ; 03  inc bc
  db 47 ^ ' '  ; 0f  rrca
  db 47 ^ 'W'  ; 78  ld a, b
  db 47 ^ 'o'  ; 40  ld b, b
  db 47 ^ 'r'  ; 5d  ld e, l
  db 47 ^ 'l'  ; 43  ld b, e
  db 47 ^ 'd'  ; 4b  ld c, e
  db 47 ^ '!'  ; 0e  ld c,
  halt         ; 76        $76
  ld a, (hl)
  inc hl
  push hl
  xor 47
               ; 32749 nop instructions, and then:
               ; putchar(A)
               ; ret

Whenever the PC becomes $8000, Z80Golf is programmed to write the byte in register A to STDOUT, and then effectively execute a ret (the PC is set to (SP) and SP is incremented by 2). In our code, instead of using call $8000 to access this behavior, we let the PC wade through a sea of nops (opcode 00) from $0013 to $7fff.

Keeping this in mind, the code will run as follows:

  • Execute some meaningless instructions (effectively NOPs), starting from ld h,a.
  • Set A to mem[0] ^ 47, which is 'H'.
  • Increment HL and push it ($0001).
  • Fall through to putchar, and return to the $0001 we pushed.
  • Execute some meaningless instructions, starting from ld c,d this time.
  • Set A to mem[1] ^ 47, which is 'e'.
  • Increment HL and push it ($0002).
  • Fall through to putchar, and return to the $0002 we pushed.
  • Set A to mem[12] ^ 47, which is '!'.
  • Fall through to putchar, and return to the $000d we pushed.
    • We finally jump into the argument of the ld c, $76 — and $76 is the halt opcode!

Of course, the constant 47 was carefully picked so that none of the first instructions 13 influence the execution of the code, and the last one is some opcode that takes a single-byte argument, “hiding” the halt opcode until we jump there after printing '!'.

\$\endgroup\$
14
+500
\$\begingroup\$

Trianguish, 187 bytes

00000000: 0a04 10c3 0201 40d9 1020 1403 a040 4d0e
00000010: 2060 4d11 040b 003c 050e 204d 0203 c027
00000020: 060c 5107 106c 1040 4d0e 2050 c310 2028
00000030: 03f0 6074 1104 10c3 0502 c04e 0203 c027
00000040: 0611 0710 c510 404d 0e20 50e0 1020 2803
00000050: a060 2f10 7107 7105 0e20 4d04 10c3 0203
00000060: c027 0710 2310 2028 03a0 404d 0e20 50c3
00000070: 1060 5d11 0203 c027 050e 204d 0410 c307
00000080: 1077 1040 4d0e 2020 2803 a050 c310 607a
00000090: 1105 0e20 4d02 03c0 2704 10c3 0710 7410
000000a0: 404d 0e20 2028 03f0 50c3 1060 6b11 0202
000000b0: 9105 0e20 4d07 1024 1050 c2            

It big :o

Try it online!


Trianguish is my newest language, a cellular automaton sort of thing which uses a triangular grid of "ops" (short for "operators"). It features self-modification, a default max int size of 216, and an interpreter which, in my opinion, is the coolest thing I've ever created (taking over forty hours and 2k SLOC so far).

This program consists of a central "spine" of wires and splitters, which transmits a 1-tick pulse of non-NIL data, and a number of "nodes" which print one character of the string as the pulse passes them.

At the start of the "spine" is a 1-tick pulse generator, one of the most basic, and important, applications of Trianguish's self-modification:

A 1-tick pulse generator

In this case, a 0 constant is used, as the actual number sent along doesn't matter, since it's used purely for timing.

Each "node" along the program consists of a T-switch, essentially a transistor, which permits an ASCII character code to flow through it for exactly one tick as the initial 1-tick pulse passes by. These character codes are produced by S-builders, which read the internal representation of an adjacent op, which in this case are tuned to match the correct characters. Only one node is different from the rest, that being the third, which instead of printing a single l splits the signal into two and prints both simultaneously. This also requires an additional delay for the next character.

\$\endgroup\$
1
  • 6
    \$\begingroup\$ Very good name. :) \$\endgroup\$ Commented Jul 30, 2022 at 9:56
13
\$\begingroup\$

BBC BASIC, 20 bytes

PRINT"Hello, World!"

Ahh, this was my first language :)

\$\endgroup\$
6
  • \$\begingroup\$ so BBC Basic does not accept ? as a shorhand for print? \$\endgroup\$
    – edc65
    Commented Aug 28, 2015 at 14:27
  • \$\begingroup\$ @edc65 I have no idea... I'll try \$\endgroup\$
    – Beta Decay
    Commented Aug 28, 2015 at 14:28
  • \$\begingroup\$ @edc65 It doesn't work in BBC BASIC for Windows \$\endgroup\$
    – Beta Decay
    Commented Aug 28, 2015 at 14:53
  • \$\begingroup\$ Strange, as it's quite standard in basic. A posted an answer as VBA \$\endgroup\$
    – edc65
    Commented Aug 28, 2015 at 14:59
  • 1
    \$\begingroup\$ @edc65, The "?" is NOT accepted, seems it conflicts with BBC Basic's PEEK() variant. But this is: P."Hello, World!" \$\endgroup\$ Commented Mar 19, 2017 at 8:31
13
\$\begingroup\$

Fission, 17 bytes

R"Hello, World!";

or

;"!dlroW, olleH"L

or any cyclic permutation of the two. In Fission, we need the R or L to release an atom and get control flow going. " toggles print mode, which just prints everything encountered until switched off. Finally ; destroys the atom to avoid an infinite loop.

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

Packed 7-bit ASCII, 12

fÍëWßËfD 

Since Markdown eats some of the characters, here's a hexdump:

$ xxd hello.ascii 
0000000: 9197 66cd eb10 57df cb66 4420            ..f...W..fD 

And yes, the trailing space is necessary.

Packed 7-bit ASCII is created by taking 8-bit ASCII (the normal kind), removing the high zero bit from each byte, packing the remainder, and then padding it out with trailing zero bits.

According to this site, this character encoding is used by "a specific US MIL STD message header format", making it a real thing.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Is Packed ASCII a programming language on its own right? \$\endgroup\$ Commented Aug 30, 2015 at 16:04
  • \$\begingroup\$ @user3819867 It's an edge case. It depends on definitions. \$\endgroup\$
    – isaacg
    Commented Aug 30, 2015 at 16:19
  • \$\begingroup\$ Packed 7-bit ASCII is the encoding SMS uses \$\endgroup\$
    – slebetman
    Commented Sep 1, 2015 at 4:31
13
\$\begingroup\$

Cubix, 31 29 bytes

Saved 2 bytes thanks to @MartinBüttner

./v.o;@?/"!dlroW"S',u/"Hello"

I proudly present Cubix, my new 2-dimensional, stack-based esolang. Cubix is different from other 2D langs in that the source code is wrapped around the outside of a cube.

Test it online! You can now adjust the iteration speed if you want it to run faster or slower.

Explanation

The first thing the interpreter does is figure out the smallest cube that the code will fit onto. In this case, the edge-length is 3. Then the code is padded with no-ops . until all six sides are filled. Whitespace is removed before processing, so this code is identical to the above:

      . / v
      . o ;
      @ ? /
" ! d l r o W " S ' , u
/ " H e l l o " . . . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .

Now the code is run. The IP (instruction pointer) starts out on the top left char of the far left face, pointing east. Here's an overview of the basic commands:

  • \|/_ are mirrors, and reflect the IP depending on the direction it's traveling.
  • >v<^ set the direction of the IP unconditionally.
  • ? turns the IP right if the top item is positive, or left if it's negative.
  • ' pushes the char code of the next char.
  • " toggles string mode, performing ' on each char until the IP encounters another ".
  • o outputs a char code.
  • ; pops an item.
  • @ ends the program.

The first char we encounter is ", which toggles string mode. Each char code is pushed to the stack until we run into the next ". Then we push a space with S, and a comma with ',. The stack now contains !dlroW ,.

Next we hit u, which turns the IP right, then right again before executing the next instruction. The IP is now at the far right of the fifth row in the above diagram, facing west. Now the IP executes "olleH", making the stack !dlroW ,olleH. The / points the IP south, where it travels through the bottom row of the bottom face, back up to the S (which adds an extra space), and finally hits the v.

Now the IP is in what I call the "output loop". First it moves down and hits the ;, which turns pops the unnecessary space. Then it hits the ?, which directs it through o to output, bounces back around to ; to pop the char, then comes back to ?.

This repeats until the stack is empty. Then, since the top of the stack is no longer truthy, ? leaves the IP headed north. The next char is @, which terminates the program.

I'm not sure if this program is optimal; there's four two no-ops which could probably be put to better use. Martin and I will keep looking to find a better solution.

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

Javascript, 22 bytes

alert("Hello, World!")

You don't NEED semicolons in Javascipt!

\$\endgroup\$
5
  • \$\begingroup\$ Don't you need them? \$\endgroup\$
    – AAM111
    Commented Apr 14, 2016 at 21:19
  • \$\begingroup\$ Apparently not for 1 liners (I don't know JS golfably) \$\endgroup\$
    – Blue
    Commented Apr 14, 2016 at 21:21
  • 1
    \$\begingroup\$ The JS interpreter will automatically insert them where it thinks they should be, if they aren't present \$\endgroup\$
    – bren
    Commented May 8, 2016 at 22:54
  • \$\begingroup\$ It does not print to stdout like the spec says \$\endgroup\$ Commented Jun 1, 2016 at 19:45
  • 3
    \$\begingroup\$ @ValentinLorentz Javascript doesn't have a stdout - I used the nearest alternate; see Default for Code Golf: Input/Output methods \$\endgroup\$
    – Blue
    Commented Jun 1, 2016 at 19:48
12
\$\begingroup\$

PDP-11 (Unix) Assembly, 33 38 bytes

Source (No trailing newline required):

sys 4;10;15;sys 1;<Hello, World!>

Binary output:

0000000 000407 000026 000000 000000 000000 000000 000000 000000
0000020 104404 000010 000015 104401 062510 066154 026157 053440
0000040 071157 062154 000041 000000 000000 000000 000000 000000
0000060 000000 000000 000000 000000 000000 000000
0000074

The output is zero-padded to 60 bytes for some reason, but I know enough about the architecture to know that it doesn't matter and can be considered 38 (maybe 37) bytes. Unfortunately, while this works on the terminal, it actually prints to STDIN.

So, a correct program (I believe it exits with status 1, but that's not important) is:

5200;sys 4;12;15;sys 1;<Hello, World!>

That 5200 in the beginning is actually an "inc r0" instruction, but writing it in octal is shorter. Coincidentally, the length of this source code is also 38 bytes.

0000000 000407 000030 000000 000000 000000 000000 000000 000000
0000020 005200 104404 000012 000015 104401 062510 066154 026157
0000040 053440 071157 062154 000041 000000 000000 000000 000000

Output clocks in at 20 non-zero words, or 39 non-zero bytes, and this time the assembler doesn't insert quite as much padding so the actual output file size is 48 bytes.

Unobfuscated source for the same program:

inc r0
sys write; 0f; 13.
sys exit
0: <Hello, World!>

If you actually assemble this source the output has an extra nonzero byte (value 2) in the second-last word of the output, probably something to do with the fact that named symbols were used for the system calls.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ So is your answer optimized for short machine code, or for short source? Or both? Maybe post two header lines, one for the machine-code count and one for the asm source count? \$\endgroup\$ Commented Apr 13, 2018 at 0:52
12
\$\begingroup\$

gs2, 2 bytes

\x12h

where \x12 is a raw byte.

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

Sed, 14 bytes

I'm hoping the sed exemption from no-input-rules applies here. If so, we can do:

cHello, World!

All that is required as input is one empty line.

\$\endgroup\$
3
  • \$\begingroup\$ cHello, World! \$\endgroup\$ Commented Aug 28, 2015 at 18:28
  • 1
    \$\begingroup\$ @MitchSchwartz excellent - I've never used the c sed command before - thanks! \$\endgroup\$ Commented Aug 28, 2015 at 18:56
  • \$\begingroup\$ Something like sed -e 'cHello, World!' <<<'' \$\endgroup\$ Commented Dec 9, 2018 at 13:41
11
\$\begingroup\$

GNU Make, 27

$(info Hello, World!)
a:;@:
\$\endgroup\$
1
  • \$\begingroup\$ You can stick these two lines together, in either order, on one line to eliminate one more char. \$\endgroup\$ Commented Mar 19, 2017 at 8:48
11
\$\begingroup\$

Carrot (version: ^3), 13 bytes

Carrot is a language of Κριτικσι Λίθος. The syntax is stack^commands, where the stack is a string, and the interpreter outputs everything that's on the stack at the end of the program. The carrot is optional if you have no commands.

Hello, World!

In version ^, the carrot wasn't optional yet if you had no commands, so then it was 14 bytes:

Hello, World!^
\$\endgroup\$
5
  • 1
    \$\begingroup\$ +6 carrot.png \$\endgroup\$ Commented Nov 1, 2015 at 18:11
  • \$\begingroup\$ Write the version number as "^". \$\endgroup\$
    – user41805
    Commented Nov 2, 2015 at 5:51
  • \$\begingroup\$ @ΚριτικσιΛίθος Sure! Done. \$\endgroup\$
    – ProgramFOX
    Commented Nov 2, 2015 at 6:40
  • \$\begingroup\$ Version ^3 makes the ^ optional is you do not want to use any commands. Thus this can be shortened down by one byte. \$\endgroup\$
    – user41805
    Commented Nov 3, 2015 at 8:40
  • \$\begingroup\$ @ΚριτικσιΛίθος Cool! Added that. \$\endgroup\$
    – ProgramFOX
    Commented Nov 3, 2015 at 8:43
11
\$\begingroup\$

VSL, 35 33 bytes

Saved 2 bytes thanks to @ASCII-Only

fn main(){print("Hello, World!")}

Try it online!

Okay after over one year development, the day has come where I can post this :D

There is a print("Hello, World!") function but this is shorter. As I seperate libc and libvsl this will probably have to switch over to print but for now this is the shortest.

\$\endgroup\$
1
  • \$\begingroup\$ Using fn can save two bytes \$\endgroup\$
    – ASCII-only
    Commented Apr 11, 2018 at 3:16
10
\$\begingroup\$

R, 20 bytes

cat("Hello, World!")
\$\endgroup\$
10
\$\begingroup\$

Prelude, 38 bytes

92480969393782833909095806(^+^+^^+++!)

If you're using the Python interpreter, you'll need to make sure that NUMERIC_OUTPUT is set to False.

Prelude is a relatively simple stack-based language, with 0-9 pushing the corresponding single digits and the only arithmetic being addition and subtraction. In particular, there is no multiplication.

To make the most of the single digit pushing behaviour, I took a look at the code points in various bases. For base 12, we get this:

[[6 0] [8 5] [9 0] [9 0] [9 3] [3 8] [2 8] [7 3] [9 3] [9 6] [9 0] [8 4] [2 9]]

Everything here is a single digit - that's perfect! This means that we can encode each character using two digits via base 12, e.g. H -> 72 (base 10) -> 60 (base 12). That's what the long string of 26 digits at the beginning is for.

The back half of the code then needs to take each pair of digits a, b and give 12*a+b. But remember, Prelude doesn't have multiplication! What it does have, however, is ^ and v, which get the top stack values from the program rows ("voices") above and below. Since this is a one-line program, ^ effectively duplicates the top of the stack, allowing us to do ^+^+^^++ to multiply the top stack element by 12. We then add the second digit with + and output with !. All of this is wrapped in (), which is a BF-like loop which executes while the top stack element is nonzero.

\$\endgroup\$
10
\$\begingroup\$

Pancake Stack, 1118 1073 bytes

Put this supercalifragilisticexpialidociouseventhoughthesoundofitissomethingquite pancake on top!
Show me a pancake!
Put this floccinaucinihilipilification pancake on top!
Put the top pancakes together!
Show me a pancake!
Put another pancake on top!
Put this piquant pancake on top!
Put the top pancakes together!
Show me a pancake!
Show me a pancake!
Put another pancake on top!
Put this big pancake on top!
Put the top pancakes together!
Show me a pancake!
Put this osteosarchaematosplanchnochondroneuromuelous pancake on top!
Show me a pancake!
Put this kolmivaihdekilowattituntimittari pancake on top!
Show me a pancake!
Put the top pancakes together!
Put this scrumptious pancake on top!
Put the top pancakes together!
Show me a pancake!
Eat the pancake on top!
Show me a pancake!
Put this big pancake on top!
Put the top pancakes together!
Show me a pancake!
Eat the pancake on top!
Show me a pancake!
Eat the pancake on top!
Take off the syrup!
Show me a pancake!
Put this nonilfenossipolietilenossietonolo pancake on top!
Show me a pancake!
Eat all of the pancakes!

I've been avoiding this one because I haven't found a good way of golfing it yet, but here's a submission for now.

The relevant operations are:

Instruction                               Result
--------------------------------------------------------------------------
Put this X pancake on top!                Push word length of X to stack
Eat the pancake on top!                   Pop and discard
Put the top pancakes together!            Add top two
Put another pancake on top!               Duplicate
Show me a pancake!                        Print as ASCII without popping
Take off the syrup!                       Decrement all stack values by 1
Eat all of the pancakes!                  Terminate program

If you take a look a Pancake Stack's full instruction set, you'll notice that you only ever have access to the top two stack elements at any time, which makes this language a pain to program in normally. That and the fact that you can only output as ASCII, i.e. no numeric output.

Note that, if you're using the Python interpreter, you'll need an extra line with a ~ afterwards if you want to test by piping in a file. We don't use it here, but anything after the ~ is treated as normal STDIN input.

\$\endgroup\$
10
\$\begingroup\$

Foo, 14 bytes

"Hello, World!

Not printing Hello World seems to be a lot harder in Foo that the opposite...

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Would s print Hello World? ;) \$\endgroup\$
    – AAM111
    Commented Apr 14, 2016 at 21:18
  • \$\begingroup\$ Probably. \$\endgroup\$
    – Dennis
    Commented Apr 14, 2016 at 21:20
  • \$\begingroup\$ If you find out, you might be able to golf it down to 0 or 1 byte! \$\endgroup\$
    – AAM111
    Commented Apr 14, 2016 at 21:22
10
\$\begingroup\$

Labyrinth, 46 45 40 bytes

72.10:1.:8:..:):1:.#2#4..:1..4.:8.0.33.@

Try it online!

Labyrinth is my new two-dimensional programming language (although the 2D'ness isn't really used here). Labyrinth operates on two stacks (although this code only uses one). Each character is a separate command. However, as opposed to most similar languages individual digits don't push that digit (which makes it annoying to build up larger numbers), instead they multiply the top of the stack by 10 before adding themselves. This allows you simply to write out the numbers you want to push. (Another language with this concept is Emmental.)

The other commands you need to know for the above code are . which prints the top of the stack (modulo 256), : which duplicates the top of the stack, ) which increments it and # which pushes the current stack depth. @ terminates the program. There's only one tricky part: W is printed by appending a 1 to 111 (o), because 1111 % 256 = 87.

Here is what the stack and output look like throughout the program:

Command(s)  Stack               Output
72          [72]                ><
.                               >H<
10          [10]                >H<
:           [10 10]             >H<
1           [10 101]            >H<
.           [10]                >He<
:           [10 10]             >He<
8           [10 108]            >He<
:           [10 108 108]        >He<
..          [10]                >Hell<
:           [10 10]             >Hell<
)           [10 11]             >Hell<
:           [10 11 11]          >Hell<
1           [10 11 111]         >Hell<
:           [10 11 111 111]     >Hell<
.           [10 11 111]         >Hello<
#           [10 11 111 3]       >Hello<
2           [10 11 111 32]      >Hello<
#           [10 11 111 32 4]    >Hello<
4           [10 11 111 32 44]   >Hello<
..          [10 11 111]         >Hello, <
:           [10 11 111 111]     >Hello, <
1           [10 11 111 1111]    >Hello, <
..          [10 11]             >Hello, Wo<
4           [10 114]            >Hello, Wo<
.           [10]                >Hello, Wor<
:           [10 10]             >Hello, Wor<
8           [10 108]            >Hello, Wor<
.           [10]                >Hello, Worl<
0           [100]               >Hello, Worl<
.           []                  >Hello, World<
33          [33]                >Hello, World<
.           []                  >Hello, World!<
@
\$\endgroup\$
3
  • 1
    \$\begingroup\$ This maybe could be golfed more if you allow the code to intersect itself. \$\endgroup\$ Commented Aug 29, 2015 at 14:24
  • \$\begingroup\$ I really don't understand why "1111" is a "W". The ascii code for 'W' is 87. Can somebody explain this to me? \$\endgroup\$ Commented May 25, 2017 at 15:29
  • \$\begingroup\$ Oh, I see the explanation in the description, but I wasn't aware that . did a % 256 before printing. \$\endgroup\$ Commented May 25, 2017 at 15:41
10
\$\begingroup\$

ELF 32-bit LSB executable (Linux), 59 bytes

0000000: 7f 45 4c 46 01 00 00 00 00 00 00 00 00 90 43 0d  .ELF..........C.
0000010: 02 00 03 00 19 90 43 0d 19 90 43 0d 04 00 00 00  ......C...C.....
0000020: b9 2e 90 43 0d b2 0d cd 80 cc 20 00 01 00 48 65  ...C...... ...He
0000030: 6c 6c 6f 2c 20 57 6f 72 6c 64 21                 llo, World!

This exits with INT 3 (breakpoint), so your shell may display a message to indicate this. However, the program itself prints nothing to STDERR.

Try it online!

Verification

$ cksum hw32
3205536342 59 hw32
$ ./hw32
Hello, World!Trace/breakpoint trap
$ ./hw32 | cat; echo
Hello, World!
$ ./hw32 | xxd -g 1
0000000: 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21           Hello, World!
\$\endgroup\$
1
10
\$\begingroup\$

USML, 9 bytes

S0h7cWs8h

Try it online!

Explanation:

S0h7cWs8h
S0h7       # Get characters 0-7 of h ("Hello, world!").
    cW     # Get the character "W"
      s8h  # Get the remaining characters, starting at character 8, of h.

This program is an interesting problem, as it has a command that outputs "Hello, world!" (and an empty program will also do this), but the capitalization is not correct. As a result, we need to take some substrings and add in the correct character.

\$\endgroup\$
1
  • 8
    \$\begingroup\$ This is probably the first interesting use of a HW-built-in I've seen in this challenge. \$\endgroup\$ Commented Apr 8, 2017 at 22:15
10
\$\begingroup\$

LLVM IR 4.0.1, 149 145 152 bytes

declare i8@puts(i8*)@t=global[14 x i8]c"Hello, World!\00"define void@main(){call i8(i8*)@puts(i8*getelementptr([14 x i8],[14 x i8]*@t,i1 0,i1 0))ret void}

I'm not very good in LLVM IR, so chances are good, that it's possible with fewer bytes.

Ungolfed Version:

declare i8 @puts(i8*) ; Declare puts from C standard. i8, was the shortest return type possible.

@t=global [14 x i8] c"Hello, World!\00" ; Hello world string as global, to have a pointer to it.

define void @main(){
    call i8(i8*) @puts(i8* getelementptr([14 x i8], [14 x i8] *@t, i1 0, i1 0)) ; Get pointer to constant "Hello, World!" and pass it to puts
    ret void
}
\$\endgroup\$
2
  • \$\begingroup\$ would int main be smaller, with ret 0 instead of ret void? I don't know LLVM IR at all, really >.< \$\endgroup\$ Commented Apr 13, 2018 at 0:54
  • \$\begingroup\$ You can put a raw null byte instead of \00, do call i8@puts, and use [14x i8] to save space \$\endgroup\$
    – EasyasPi
    Commented Dec 30, 2020 at 20:39
10
\$\begingroup\$

قلب repl, 21 bytes

قول"Hello, world!"

Online repl

Qalb is a programming language designed for Arabic speakers as opossed to the anglophone stance of most popular programming languages.

I took this program from wikipedia and fiddled around with it, managing to save 3 bytes. If you were wondering, قول means "say".

I haven't managed to get a full implementation running on my computer so for now I am just using the repl.

\$\endgroup\$
9
\$\begingroup\$

Ruby, 18 19 bytes

puts"Hello, World!"

Output wasn't quite right. Thanks Martin

\$\endgroup\$
2
  • \$\begingroup\$ Why not p"Hello, World!"? It's only 15 bytes. \$\endgroup\$
    – John
    Commented Jan 29, 2016 at 23:37
  • 2
    \$\begingroup\$ @John: p always always prints quotes around strings. \$\endgroup\$
    – univalence
    Commented Jul 18, 2016 at 18:22
9
\$\begingroup\$

Mouse, 19 bytes

"Hello, World"33!'$

Oddly enough, ! inside of a string makes a newline, so we have to work around that by getting the ASCII code for !, which is 33, and outputting that as a character.

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

COBOL, 55 bytes

PROGRAM-ID.H.PROCEDURE DIVISION.DISPLAY"Hello, World!".

Thankfully not quite as verbose as some ancient bloated languages like Java.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ You're cheating. Last I checked, COBOL needed a lot of newlines and useless spaces at the start of each line... \$\endgroup\$ Commented Dec 15, 2015 at 11:05
  • 1
    \$\begingroup\$ When I compile that at tutorialspoint.comcompile_cobol_online.php it says Error: syntax error, unexpected "end of file", expecting "FUNCTION-ID" or "PROGRAM-ID" because it doesn't like the missing newlines. The exact same code on three lines compiles and runs. \$\endgroup\$ Commented Mar 17, 2016 at 23:34
  • 1
    \$\begingroup\$ @JerryJeremiah This works just fine with GNU COBOL, assuming you provide the -F (or -free) flag. tio.run/##S85Pys/RTc8r/f8/… \$\endgroup\$
    – Dennis
    Commented Jul 17, 2017 at 20:45
9
\$\begingroup\$

???, 96 bytes

,;;..;...;.;,,,,;,,"......";...........-,'",-.";;,,,,!;...!;,!!...!;;;!-!-!-!...!,,,,,,!-,!;;;.!

Based on the 95-byte approach by Mitch Schwartz.

Note that the 92-byte Brainfuck solution would yield 97 bytes in ???, because the sequential loops require four more apostrophes.

\$\endgroup\$
2
  • 25
    \$\begingroup\$ This is... wait, wrong challenge. \$\endgroup\$
    – Dennis
    Commented Aug 29, 2015 at 4:38
  • \$\begingroup\$ 80 bytes \$\endgroup\$
    – ASCII-only
    Commented Apr 12, 2018 at 5:24
1 2
3
4 5
34

Your Answer

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

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