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
13 14
15
16 17
34
2
\$\begingroup\$

RPython, 60 bytes

def e():print'Hello, World!';return 0
target=lambda*_:e,None
\$\endgroup\$
2
\$\begingroup\$

awk, 25 bytes

END{print"Hello, World!"}
\$\endgroup\$
4
  • \$\begingroup\$ I know little of awk, but I think you can remove the END part. (It's June I know). \$\endgroup\$ Commented Jun 2, 2016 at 19:30
  • \$\begingroup\$ Actually, if you use END, it requires some kind of input... the input can be empty but it seems to be needed on my version of AWK. You do need a label, though, otherwise nothing will happen. BEGIN works, but it adds 2 bytes. :( \$\endgroup\$ Commented Jul 19, 2016 at 13:11
  • 1
    \$\begingroup\$ You're both right(ish). If you can invoke the one blank line of input rule you don't need the END, otherwise you must use BEGIN not END. \$\endgroup\$ Commented Mar 19, 2017 at 8:53
  • 1
    \$\begingroup\$ If the one-blank-input rule is allowed, this works too $0="Hello World!" \$\endgroup\$
    – cnamejj
    Commented Apr 14, 2021 at 10:06
2
\$\begingroup\$

Erlang, 63 bytes

Save as h.erl, then compile with erl -s h m, I think.

-module h.
-export[m/0].
m()->io:fwrite("Hello, World!").
\$\endgroup\$
2
\$\begingroup\$

Glypho, 480 bytes

In the "shorthand" format, it's 120 bytes:

1d+d1+d*+ddd++ddd++1+d11+d*d++d11+1+d++d1-dd+++d1<d>+-d++11+d*d*d+<d>d+d+d<d>+d+1+d1-dd+++d1-<d>+d*1+11+1+d+d*d+<d-+>[o]

An example conversion to "true" Glypho (using the translation of the Java interpreter, which differs slightly from that documented in the esolangs.org page) is:

v># #  :: < <   <v#  #*>*> ##:#**#,<,<: : > > *  *v>>v # ##,#, + +:++: ++ ##
*<<*,^,^<<#v<<v#v::v< < <,, +,+,+>>+*,,*+*+*,,*>**^v#  #,,:^#vv#>+>+ << >  >, , ++*>:
:v<v<^#^#v::v>::>v**v # #::>^>+>>:>:>>>*>>##>*^ *# #  vv ,::,<<>:++
*vv*v:v:^vv< > > ,,>>:>: << >+>>^ ^ ^^*^+,+,#::#*:*::  :v v  ,   # #<<#<#**#^,^,+##+**
+**+,:,:::>*<^v< v v+^+^*^^*+<<++##+v#v#++<>:< :* **+ +   ^ *  *<+<+<  *vv+<:^^:::
^+*<<***<^+  ++:+:^##^:>:>+::< > >#>># *  >,>, :^ ^>>^##<#,<,*^   *<:<

(using Windows line terminators \r\n) where I tried to disguise it as a 2D language for the Programming Language Quiz.

The basic approach is to push onto the stack a 0 followed by the codepoints in reverse order, and then print them with the loop [o]. In order to golf the pushing, I first push 11 and then I can push a new 11 whenever I want with <d>; the final <d-+> replaces that 11 on the bottom of the stack with the desired 0.

I experimented with various values on the bottom of the stack, and 11 is the only one for which my brute-force searcher was able to find expressions for each of the characters which were no more than 11 bytes each. (12 bytes was taking too long).

\$\endgroup\$
1
  • \$\begingroup\$ Quick translation from my CSL answer (i.e. super suboptimal), 456 \$\endgroup\$
    – ASCII-only
    Commented Apr 13, 2018 at 6:32
2
\$\begingroup\$

23, 52 bytes

17,13,72,101,108,108,111,44,32,87,111,114,108,100,33

This uses 23.dezsy notation: 17,13 prints the 13 integers that follow as characters.

Try it online here. (Don't forget to replace the example with the above source code.)

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

Maxima, 23 bytes

print("Hello, World!")$
\$\endgroup\$
2
\$\begingroup\$

UNBABTIZED

:72.:101.:108.:108.:111.:44.:32.:87.:111.:114.:108.:100.:33

:x prints x as a character and . acts as a statement separator.

The official interpreter is written for Python 2.2. You can use it in modern versions of Python by prepending the line

# coding: latin1
\$\endgroup\$
2
\$\begingroup\$

az, 16 bytes

"Hello, World!".
\$\endgroup\$
2
\$\begingroup\$

Cardinal, 15 bytes

%"Hello, World!
\$\endgroup\$
2
\$\begingroup\$

LMNtal, 35 bytes

io.use.io.print("Hello, World!",_).

A weird programming language from Japan that seems to be inspired by Prolog.

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

Fishing, 37 bytes

v+CCCCCCCCCCCCCCCC
  `Hello, World!`N

I don't think there's anything to golf beyond the example listed on the esolangs page, so I didn't really write this myself. Hence, community wiki.

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

HPPPL, 44 43 bytes

HP Prime Programming Language for the HP Prime color graphing calculator.

export h()begin print("Hello, World!");end;

(golfed down by one byte, thanks to kirbyfan64sos!)

Output:

Hello, World! HPPPL

This is a full program that you call by entering h to start it.

If you just want to have the output to the terminal, then a shorter (22 bytes) version in Home Mode works, too:

print("Hello, World!")

A free emulator is available here: http://www.hp-prime.de/en/category/13-emulator

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is the space between the right parenthesis and begin needed? \$\endgroup\$ Commented Sep 1, 2015 at 13:55
  • \$\begingroup\$ @kirbyfan64sos Thanks for the hint. No, it’s not necessary. \$\endgroup\$
    – M L
    Commented Sep 1, 2015 at 14:30
2
\$\begingroup\$

RUBE, 47 bytes

A cellular automaton-based language about warehouses, crates, dozers, and conveyor belts:

2
1
766
2c4
256
07f
662
cfc
466
85c
OOO
ccc
===

It turns out stacking all the crates on top of each other like 2\n1\n6\n... is also 57 bytes, and is "simpler", but I didn't want to stretch the page. :)

Update: stacking the crates into a rectangle is shorter! Who'd've thought?

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

Doorspace, 92 bytes

The language is also known as Qugord.

~group h from %2 to %14 affect h into "Hello, World!" each h into 0 task give 0 to 1 publish

or

~group h from 0 to %12 affect h into "Hello, World!" each h into 0 task give 0 to %0 publish

It's seriously bugging me that this has a horizontal scrollbar because of a single character. I don't see how to shorten it any further though.

This solution is mostly a golfed version of the "Hello, World!" example on the esolangs page. The important concepts of the language are that it operates on an infinite main array, initialised to zeroes; and then there's also an output array, which is reset every time you print its contents. If you know what the commands mean, the code is actually quite readable if split across several lines (which is not valid in the language):

group h from %2 to %14 
affect h into "Hello, World!" 
each h into 0 task 
  give 0 to 1 
  publish

The first line defines a "group tag" h, which is some subarray of the main array. In this case, it addresses the cells at indices 2 to 14 (leaving 2 cells for future use).

The second line writes the character codes of Hello, World! into these 13 cells.

The third line defines a foreach loop over the cells in h, which works by copying the current value into the specified cell (0) and then executing the code after it.

The fourth line is executed once for each character code (which we find in cell 0). It moves the character code from the 0th cell of the main array to the 0th cell of the output array (which we index relatively by looking at index 1 on the main tape, which is zero).

The fifth line prints everything in the output array up to the last non-zero element (i.e. just the first cell in our case).

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

Parenthetic, 1036 Bytes

This can undoubtedly be done better, but it's about the best I can come up with at the moment.

((()()())(()()()())((()()(()))((())()()()())((())()()()()()()()())))((()()())(()(())())((()(()))(()()()())((())()()()())))((()()())(()()(()()))((()()(()))(()()()())((())()()())))((()()())(()(()())())((()()(()))(()(())())((())()()())))((()(())()(()))((()((()))())((()(())(())())((()()(()))(()(())())((())()())))((()((()))())((()(())(())())((()(()))(()()(()()))((())()()()()())))((()((()))())((()(())(())())(()(()())()))((()((()))())((()(())(())())(()(()())()))((()((()))())((()(())(())())((()(()))(()(()())())((())()()())))((()((()))())((()(())(())())((()(()))(()()()())((())()()()()()()()()()()()())))((()((()))())((()(())(())())(()()()()))((()((()))())((()(())(())())((()(()()))(()()(()()))((())()()()()()()()()())))((()((()))())((()(())(())())((()(()))(()(()())())((())()()())))((()((()))())((()(())(())())((()(()))(()(()())())((())()()()()()())))((()((()))())((()(())(())())(()(()())()))((()((()))())((()(())(())())((()(()))(()()(()()))((())()()()())))((()((()))())((()(())(())())((()(()))(()()()())((())())))(()((())))))))))))))))))

General Steps

Define A 32
Define B 36
Define C 32 * 3
Define D 36 * 3
Build a list of chars with (A*2)(C+5)(D)(D)(D+3)(A+12)(A)(C-9)(D+3)(D+6)(D)(C+4)(A+1)
Output list + empty set as string

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

l33t, 104 bytes

7 99999998 1 7 9991 1 7 6 1 1 7 2 1 5 0 7 99997 1 8 92 1 6 0 8 995 1 7 995 1 7 2 1 8 5 1 8 7 1 5 0 7 0 1

I've been using the Ruby interpreter which seems to insert an 10 (END) at the end of the code implicitly.

l33t is supposed to look like l33t-5p34k. However, it is interpreted by simply summing the digits in each "word" and turning that into an opcode. So for golfing all we want is those digits. Golfing l33t like this is definitely living on the edge though. Quoting from the language spec:

It is possible to program in l33t just using numbers, i.e. not forming letters in l33t 5p34k. However, programmers who do this are teh sUxX0r, and the interpreter is well within its rights to format your hard drive for attempting this.

As for the language itself, it's basically a Brainfuck-derivative. The main differences are that the source code is living on the tape as well (with an independent memory and instruction pointer), and that you define an offset whenever you move forward, backward, increment or decrement (so you can make larger jumps and increment more efficiently). Therefore, the techniques used in the short Brainfuck solutions don't help much here.

I started out with the naive solution (increment/decrement to value, print, repeat). That was 105 bytes. I managed to shave off one byte by computing the symbols , ! on a different memory cell than the letters (because the offsets from o to ,, space to W and d to ! are expensive. I think I might be able to save a few more by jumping into the program memory, but I'll have to try that tomorrow.

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

Wake, 16 bytes

:"Hello, World!"

Not much room for golfing.

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

ShortScript, 2 bytes

By using the function from the standard library:

$H

And by not using it:

→Hello, World!
\$\endgroup\$
6
  • \$\begingroup\$ That library seems to be missing from your reference implementation on Esolang. \$\endgroup\$
    – Dennis
    Commented Sep 4, 2015 at 14:17
  • \$\begingroup\$ Yes, I the current version is a bit buggy \$\endgroup\$ Commented Sep 4, 2015 at 16:58
  • \$\begingroup\$ I have updated the esolangs page. Now it will work. \$\endgroup\$ Commented Sep 4, 2015 at 17:48
  • \$\begingroup\$ That implementation doesn't seem to print the exclamation point. \$\endgroup\$
    – Dennis
    Commented Sep 4, 2015 at 17:58
  • \$\begingroup\$ I will fix it tomorrow, when I am at PC. \$\endgroup\$ Commented Sep 5, 2015 at 21:02
2
\$\begingroup\$

Scheme, 24 26 25 bytes

(write "Hello, World!")

(display"Hello, World!")

simple but no one has done it in this language yet.

edit: fixed the quotes being printed.

\$\endgroup\$
5
  • \$\begingroup\$ i changed the code a little so it doesn't show the quotes \$\endgroup\$
    – Buzz
    Commented Aug 31, 2015 at 14:20
  • \$\begingroup\$ Are the quote marks necessary in case of display? The H in Hello needs to be upper-case btw. \$\endgroup\$
    – CodeManX
    Commented Sep 3, 2015 at 0:16
  • \$\begingroup\$ @CoDEmanX Yeah the quotes are necessary. Otherwise it thinks its a variable. \$\endgroup\$
    – Buzz
    Commented Sep 3, 2015 at 13:30
  • \$\begingroup\$ Sure you can't get rid of the space before "? \$\endgroup\$
    – lynn
    Commented Sep 4, 2015 at 14:08
  • \$\begingroup\$ That space can be removed. Normally scheme needs the spaces to tell two things apart. but in this case it doesn't need it \$\endgroup\$
    – Buzz
    Commented Sep 4, 2015 at 14:28
2
\$\begingroup\$

Sieve, 69 bytes

+|72|.+|101|.+|108|..>+|111|.>+|44|.-|32|.+|87|.<.+++.<.-|100|.-|33|.

Sieve is a BF-like programming language. It adds a special command |X|, called a sieve, that executes the command before it until the selected tape unit is equal to the number within the sieve. +|72|. outputs the character 72, which is an "H".

Here's an alternative with the same byte count:

+|72|.+|101|.+|108|..>+|111|.>+|44|.-|32|.>+|87|.<<.+++.<.-|100|.>>+.

The only change is that it saves 32 (space) and uses it later to print 33 (!).

\$\endgroup\$
5
  • \$\begingroup\$ Can you save some bytes by leaving the cell of the space untouched for World and then going back to it to print ! with a simple +.? \$\endgroup\$ Commented Sep 5, 2015 at 21:24
  • \$\begingroup\$ @MartinBüttner Yes, oops. \$\endgroup\$ Commented Sep 5, 2015 at 21:26
  • \$\begingroup\$ @MartinBüttner Actually, the byte count is the same. \$\endgroup\$ Commented Sep 5, 2015 at 21:29
  • \$\begingroup\$ +|72|.+|101|.>+|108|..>+|111|.>+|44|.-|32|.+|87|.<.+++.<.<-.-|33|. for 66 \$\endgroup\$
    – Sp3000
    Commented Sep 6, 2015 at 5:33
  • \$\begingroup\$ @Sp3000 Welp, already getting my butt kicked at my own language. \$\endgroup\$ Commented Sep 6, 2015 at 20:07
2
\$\begingroup\$

Ceylon, 40 bytes (or 24)

A file with this content can be executed in the Ceylon IDE:

shared void h(){print("Hello, World!");}

As Ceylon has no "top-level procedural code", all code needs to be either in a class or in a function. And only shared functions/classes can be called from outside ... and the IDE will chose the only shared function or class, if there is only one.

The Ceylon Web runner seems not to accept that text (it complains that "shared declaration is not a member of a class, interface, or package"), but instead allows directly statements:

print("Hello, World!");

(I guess the entered text is automatically wrapped in a function, and you can't declare stuff inside a function shared.)

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

Monkeys, 505 bytes

6 DOWN
6 DOWN
7 RIGHT
7 RIGHT
6 LEFT
5 DOWN
5 DOWN
5 DOWN
7 BOND
6 BOND
6 BOND
7 YELL
7 DOWN
6 DOWN
6 BOND
7 LEFT
6 LEFT
7 YELL
7 LEFT
7 LEFT
6 BOND
6 LEFT
6 LEFT
7 YELL
7 YELL
6 LEFT
6 LEFT
6 LEFT
7 YELL
5 BOND
7 LEFT
7 YELL
6 LEFT
6 LEFT
6 LEFT
6 LEFT
5 BOND
7 YELL
7 DOWN
7 DOWN
7 DOWN
5 DOWN
5 DOWN
5 DOWN
5 BOND
7 YELL
6 LEFT
7 DOWN
6 BOND
7 DOWN
7 YELL
7 LEFT
7 LEFT
7 LEFT
7 YELL
7 LEFT
6 LEFT
5 BOND
5 BOND
5 BOND
7 YELL
7 LEFT
6 DOWN
6 DOWN
6 BOND
7 LEFT
7 YELL
7 LEFT
6 DOWN
6 DOWN
6 BOND
7 YELL

I wanted to post this one for a while, but the interpreter had several bugs. However, David Catt (the author) was kind enough to upload a new, working interpreter, so I got to work...

I have no idea how to golf this language effectively, because there are so many things which are interacting. My basic approach was this:

  • Move monkeys 5, 6 and 7 to the bottom row, like this:

    ..!1.!....
    .......2!.
    .........!
    .3.!......
    .......!..
    .!....!...
    ....!4....
    ........!.
    ......!...
    ..576...!.
    

    At this point they have values 1, 1, 2.

  • This gives me comparably flexible operations: I can increment 5 and 7, or 7 and 6. I can decrement each one individually. And I can multiply 7 by the value of either 5 or 6 (mod 256).

  • So I just wrote a simple Mathematica program to look into short ways to get 7 to the next value via a few multiplications and de/increments. This search was not exhaustive, but provided much better results than naively incrementing/decrementing to the next value.

There are many more opportunities to golf this though:

  • One can use the other arithmetic operators, particularly addition and subtraction could be useful.
  • I'm always using 7 for printing - allowing 5 or 6 to print (or involving even more monkeys) might shorten things.
  • One could try to store some useful values like 111 or 32 in a monkey for later use.
  • Arrange the monkeys vertically, so that one could use UP instead of LEFT.
  • Maybe this can even be shortened with loops.

...but the language is so complicated that I'm not sure how to explore these possibilities systematically.

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

Symball, 47 bytes

'0H'0e'0l'0l'0o*59$-$1$'1$'0_'0W'0o'0r'0l'0d'1-

Try it here. (dead link)

\$\endgroup\$
2
  • \$\begingroup\$ The link is dead. \$\endgroup\$ Commented Sep 30, 2015 at 0:20
  • \$\begingroup\$ That's unfortunate. I've replaced the link at the top with a link to the Esolang page, but unless the website comes back, there are no docs and no interpreter... \$\endgroup\$
    – Dennis
    Commented Sep 30, 2015 at 0:25
2
\$\begingroup\$

C#, 67 Bytes

class a{static void Main(){System.Console.Write("Hello, World!");}}
\$\endgroup\$
2
  • \$\begingroup\$ This has been posted before \$\endgroup\$
    – RobIII
    Commented Oct 2, 2015 at 13:03
  • \$\begingroup\$ I missed it. Sorry. \$\endgroup\$ Commented Oct 2, 2015 at 18:07
2
\$\begingroup\$

Minkolang 0.1, 18 bytes

"Hello world!"(O).

"Hello world!" is pushed onto the stack in reverse order (by Minkolang), then (O) repeatedly prints the top of stack (as it's a while loop) until it's empty, at which point the program counter proceeds to . and terminates.

\$\endgroup\$
6
  • \$\begingroup\$ From the explanation, it sounds like the parentheses can be dropped. But correct me if I'm wrong. \$\endgroup\$ Commented Oct 16, 2015 at 11:17
  • \$\begingroup\$ @SuperJedi224: The parentheses are the while loop. The O outputs the top of stack as a character. \$\endgroup\$ Commented Oct 16, 2015 at 17:08
  • \$\begingroup\$ But I think you can just do that once without the loop. \$\endgroup\$ Commented Oct 16, 2015 at 19:29
  • \$\begingroup\$ @SuperJedi224: It would only output "H". \$\endgroup\$ Commented Oct 16, 2015 at 20:13
  • \$\begingroup\$ Oh, so it pushes the individual characters and not the entire string at once. Thanks for explaining that for me. \$\endgroup\$ Commented Oct 16, 2015 at 20:33
2
\$\begingroup\$

BotEngine, 2x15=30

vHello, World!
>eeeeeeeeeeeeeP
\$\endgroup\$
0
2
\$\begingroup\$

Ouroboros, 27

S"Hello, World!"1(
13wSoL!(

The program consists of two lines of code, each of which represents an ouroboros snake.

Snake 1

S sets the snake's active stack to the shared stack. The string literal pushes the character codes of Hello, World! in reverse order. Finally, 1( causes the snake to swallow the last character of its tail. Since this is the instruction that the IP is currently on, the snake dies.

Snake 2

13w causes the snake to wait for 13 ticks (so snake 1 can finish pushing the string). S switches to the shared stack and o outputs a character. L! pushes the length of the shared stack and logically negates it, resulting in 1 if the stack is empty and 0 if not. ( swallows that many characters of the snake's tail. If the stack is not yet empty, nothing is swallowed, and control loops back to the head of the snake, where it waits a while, sets the active stack as the shared stack, and outputs the next character. Once all the characters have been output, L! gives 1, and the snake swallows its IP and dies.

See it in action via Stack Snippet:

// Define Stack class
function Stack() {
  this.stack = [];
  this.length = 0;
}
Stack.prototype.push = function(item) {
  this.stack.push(item);
  this.length++;
}
Stack.prototype.pop = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack.pop();
    this.length--;
  }
  return result;
}
Stack.prototype.top = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack[this.length - 1];
  }
  return result;
}
Stack.prototype.toString = function() {
    return "" + this.stack;
  }

// Define Snake class
function Snake(code) {
  this.code = code;
  this.length = this.code.length;
  this.ip = 0;
  this.ownStack = new Stack();
  this.currStack = this.ownStack;
  this.alive = true;
  this.wait = 0;
  this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
    if (!this.alive) {
      return null;
    }
    if (this.wait > 0) {
      this.wait--;
      return null;
    }
    var instruction = this.code.charAt(this.ip);
    var output = null;
    if (this.partialString !== null) {
      // We're in the middle of a double-quoted string
      if (instruction == '"') {
        // Close the string and push its character codes in reverse order
        for (var i = this.partialString.length - 1; i >= 0; i--) {
          this.currStack.push(this.partialString.charCodeAt(i));
        }
        this.partialString = null;
      } else {
        this.partialString += instruction;
      }
    } else if (instruction == '"') {
      this.partialString = "";
    } else if ("0" <= instruction && instruction <= "9") {
      if (this.partialNumber !== null) {
        this.partialNumber = this.partialNumber + instruction; // NB: concatenation!
      } else {
        this.partialNumber = instruction;
      }
      next = this.code.charAt((this.ip + 1) % this.length);
      if (next < "0" || "9" < next) {
        // Next instruction is non-numeric, so end number and push it
        this.currStack.push(+this.partialNumber);
        this.partialNumber = null;
      }
    } else if ("a" <= instruction && instruction <= "f") {
      // a-f push numbers 10 through 15
      var value = instruction.charCodeAt(0) - 87;
      this.currStack.push(value);
    } else if (instruction == "$") {
      // Toggle the current stack
      if (this.currStack === this.ownStack) {
        this.currStack = this.program.sharedStack;
      } else {
        this.currStack = this.ownStack;
      }
    } else if (instruction == "s") {
      this.currStack = this.ownStack;
    } else if (instruction == "S") {
      this.currStack = this.program.sharedStack;
    } else if (instruction == "l") {
      this.currStack.push(this.ownStack.length);
    } else if (instruction == "L") {
      this.currStack.push(this.program.sharedStack.length);
    } else if (instruction == ".") {
      var item = this.currStack.pop();
      this.currStack.push(item);
      this.currStack.push(item);
    } else if (instruction == "m") {
      var item = this.ownStack.pop();
      this.program.sharedStack.push(item);
    } else if (instruction == "M") {
      var item = this.program.sharedStack.pop();
      this.ownStack.push(item);
    } else if (instruction == "y") {
      var item = this.ownStack.top();
      this.program.sharedStack.push(item);
    } else if (instruction == "Y") {
      var item = this.program.sharedStack.top();
      this.ownStack.push(item);
    } else if (instruction == "\\") {
      var top = this.currStack.pop();
      var next = this.currStack.pop()
      this.currStack.push(top);
      this.currStack.push(next);
    } else if (instruction == "@") {
      var c = this.currStack.pop();
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(c);
      this.currStack.push(a);
      this.currStack.push(b);
    } else if (instruction == ";") {
      this.currStack.pop();
    } else if (instruction == "+") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(a + b);
    } else if (instruction == "-") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(a - b);
    } else if (instruction == "*") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(a * b);
    } else if (instruction == "/") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(a / b);
    } else if (instruction == "%") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(a % b);
    } else if (instruction == "_") {
      this.currStack.push(-this.currStack.pop());
    } else if (instruction == "I") {
      var value = this.currStack.pop();
      if (value < 0) {
        this.currStack.push(Math.ceil(value));
      } else {
        this.currStack.push(Math.floor(value));
      }
    } else if (instruction == ">") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(+(a > b));
    } else if (instruction == "<") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(+(a < b));
    } else if (instruction == "=") {
      var b = this.currStack.pop();
      var a = this.currStack.pop();
      this.currStack.push(+(a == b));
    } else if (instruction == "!") {
      this.currStack.push(+!this.currStack.pop());
    } else if (instruction == "?") {
      this.currStack.push(Math.random());
    } else if (instruction == "n") {
      output = "" + this.currStack.pop();
    } else if (instruction == "o") {
      output = String.fromCharCode(this.currStack.pop());
    } else if (instruction == "r") {
      var input = this.program.io.getNumber();
      this.currStack.push(input);
    } else if (instruction == "i") {
      var input = this.program.io.getChar();
      this.currStack.push(input);
    } else if (instruction == "(") {
      this.length -= Math.floor(this.currStack.pop());
      this.length = Math.max(this.length, 0);
    } else if (instruction == ")") {
      this.length += Math.floor(this.currStack.pop());
      this.length = Math.min(this.length, this.code.length);
    } else if (instruction == "w") {
      this.wait = this.currStack.pop();
    }
    // Any instruction not covered by the above cases is ignored
    if (this.ip >= this.length) {
      // We've swallowed the IP, so this snake dies
      this.alive = false;
      this.program.snakesLiving--;
    } else {
      // Increment IP and loop if appropriate
      this.ip = (this.ip + 1) % this.length;
    }
    return output;
  }

// Define Program class
function Program(source, speed, io) {
  this.sharedStack = new Stack();
  this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
    var snake = new Snake(snakeCode);
    snake.program = this;
    snake.sharedStack = this.sharedStack;
    return snake;
  }.bind(this));
  this.snakesLiving = this.snakes.length;
  this.io = io;
  this.speed = speed || 10;
  this.halting = false;
}
Program.prototype.run = function() {
  if (this.snakesLiving) {
    this.step();
    this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
  }
}
Program.prototype.step = function() {
  for (var s = 0; s < this.snakes.length; s++) {
    var output = this.snakes[s].step();
    if (output) {
      this.io.print(output);
    }
  }
}
Program.prototype.halt = function() {
  window.clearTimeout(this.timeout);
}
var ioFunctions = {
  print: function(item) {
    var stdout = document.getElementById('stdout');
    stdout.value += "" + item;
  },
  getChar: function() {
    if (inputData) {
      var inputChar = inputData[0];
      inputData = inputData.slice(1);
      return inputChar.charCodeAt(0);
    } else {
      return -1;
    }
  },
  getNumber: function() {
    while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
      inputData = inputData.slice(1);
    }
    if (inputData) {
      var inputNumber = inputData.match(/\d+/)[0];
      inputData = inputData.slice(inputNumber.length);
      return +inputNumber;
    } else {
      return -1;
    }
  }
};
var program = null;
var inputData = null;

function resetProgram() {
  var stdout = document.getElementById('stdout');
  stdout.value = null;
  if (program !== null) {
    program.halt();
  }
  program = null;
  inputData = null;
}

function initProgram() {
  var source = document.getElementById('source'),
    stepsPerSecond = document.getElementById('steps-per-second'),
    stdin = document.getElementById('stdin');
  program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
  inputData = stdin.value;
}

function runBtnClick() {
  if (program === null || program.snakesLiving == 0) {
    resetProgram();
    initProgram();
  } else {
    program.halt();
    var stepsPerSecond = document.getElementById('steps-per-second');
    program.speed = +stepsPerSecond.innerHTML;
  }
  program.run();
}

function stepBtnClick() {
  if (program === null) {
    initProgram();
  } else {
    program.halt();
  }
  program.step();
}
.container {
  width: 100%;
  padding: 6px 0;
}
.so-box {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-weight: bold;
  color: #fff;
  text-align: center;
  padding: .3em .7em;
  font-size: 1em;
  line-height: 1.1;
  border: 1px solid #c47b07;
  -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
  background: #f88912;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
  display: inline-block;
  border-radius: 6px;
  float: left;
  margin-right: 25px;
  cursor: pointer;
}
.option {
  padding: 10px 20px;
  margin-right: 25px;
  float: left;
}
h1 {
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
}
a {
  text-decoration: none;
}
input,
textarea {
  box-sizing: border-box;
}
textarea {
  display: block;
  white-space: pre;
  overflow: auto;
  height: 40px;
  width: 100%;
  max-width: 100%;
  min-height: 25px;
}
span[contenteditable] {
  padding: 2px 6px;
  background: #cc7801;
  color: #fff;
}
#stdout-container,
#stdin-container {
  height: auto;
}
#stdin-container {
  display: none;
}
#reset {
  float: right;
}
#source-display-wrapper {
  display: none;
  width: 100%;
  height: 100%;
  overflow: auto;
  border: 1px solid black;
  box-sizing: border-box;
}
#source-display {
  font-family: monospace;
  white-space: pre;
  padding: 2px;
}
.activeToken {
  background: #f88912;
}
.clearfix:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.clearfix {
  display: inline-block;
}
* html .clearfix {
  height: 1%;
}
.clearfix {
  display: block;
}
<!--
Designed and written 2015 by D. Loscutoff
Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: http://codegolf.stackexchange.com/a/40331/16766
-->
<div class="container">
  <textarea id="source" placeholder="Enter your program here" wrap="off">S"Hello, World!"1(
13wSoL!(</textarea>
  <div id="source-display-wrapper">
    <div id="source-display"></div>
  </div>
</div>
<div id="stdin-container" class="container">
  <textarea id="stdin" placeholder="Input" wrap="off"></textarea>
</div>
<div id="controls-container" class="container clearfix">
  <input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" />
  <input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" />
  <input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" />
  <input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" />
</div>
<div id="stdout-container" class="container">
  <textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea>
</div>
<div id="options-container" class="container">
  <div class="option so-box">Steps per Second: <span id="steps-per-second" contenteditable>100</span>
  </div>
</div>

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

AniRad, 237 bytes

I doubt if this is the shortest solution:

 # # #   # # # #
#5+7*3      *2  =C
 / * +       *
#9*9+9+5+6      =C
   + *   +
#> 9*9+1+9  +9+8=C
   +     +   * *
#^ 9     > 4*6  =C
     +     *
#9+1*9+9+5+3  +4=C
   + -     * - +
#  6-6  +4*9+8 1=C
   = =     = = =
   C C     C C C

This is a 2D esolang which looks a bit like a magic square. This is a very early stage of the language, so a lot of new functions etc. will come in the future.

The # is the starting point of the pointer. The interpreter goes through every starting point. The order is based on the position of the #:

   4 5 6 7
   # # # #
1 #

2 #
 
3 #

If the position of the starting point is on the left, the pointer direction is right. If the position of the starting point is on the top, the pointer direction is down.

The +, -, * and / are just basic math operators. After reading a number from the pointer, every other number on it's path will be ignored until an operation has been executed, e.g. #4+3 5-2= is equivalent to #4+3-2=

The direction of the pointer can be changed with >, ^, < and v

To output a char, we use the =C. This outputs the result of all the math operators and converts the int to a char. If = is used, the interpreter will only print the result.

Here are all the paths executed in the program:

(1)  5+7*3*2           = (((5+7)*3)*2)            = 72  = H
(2)  9*9+9+5+6         = ((((9*9)+9)+5)+6)        = 101 = e
(3)  9*9+1+9+9+8       = (((((9*9)+1)+9)+9)+8)    = 108 = l
(4)  9*9+1+9+9+8       = (((((9*9)+1)+9)+9)+8)    = 108 = l
(5)  9+1*9+9+5+3+4     = (((((9+1)*9)+9)+5)+3)+4) = 111 = o
(6)  6-6+4*9+8         = ((((6-6)+4)*9)+8)        = 44  = ,
(7)  5/9*9+1+9+9+8     = ((((((5/9)*9)+1)+9)+9)+8)= 32  = 
(8)  7*9+9+9+6         = ((((7*9)+9)+9)+6)        = 87  = W
(9)  3+9*9+9-6         = ((((3+9)*9)+9)-6)        = 111 = o
(10) 6+9+4*6           = (((6+9)+4)*6)            = 114 = r
(11) 4*3*9             = ((4*3)*9)                = 108 = l
(12) 2*9*6-8           = (((2*9)*6)-8)            = 100 = d
(13) 8*4+1             = (8*4)+1                  = 33  = !
\$\endgroup\$
2
\$\begingroup\$

Mathematica, 21 bytes

Print@"Hello, World!"

Mathemaica 10.3, 20 bytes

Echo@"Hello, World!"
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Feel free to count the 10.3 version as the main solution and include the older one for reference. \$\endgroup\$ Commented Nov 10, 2015 at 13:38
2
\$\begingroup\$

Kotlin, 49 bytes

fun main(a:Array<String>){print("Hello, World!")}

This is a programming language created by JetBrains to overcome the limitations of Java (like Scala), be fast (like Java itself) and yet retain full interoperability with Java. This means that Kotlin can easily call Java code ... and vice versa.

\$\endgroup\$
1
13 14
15
16 17
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.