421
\$\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 = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

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,
      });
    else console.log(body);
  });
  
  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('<a>'+lang+'</a>').text();
    
    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
  });

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

  langs.sort(function (a, b) {
    if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) 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;
  display: block !important;
}

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

#language-list {
  padding: 10px;
  width: 500px;
  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/all.css?v=ffb5d0584c5f">
<div id="language-list">
  <h2>Shortest Solution 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>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
  • 2
    \$\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\$ – Martin Ender Aug 28 '15 at 13:56
  • 6
    \$\begingroup\$ If the same program, such as "Hello, World!", is the shortest in many different and unrelated languages, should it be posted separately? \$\endgroup\$ – aditsu Aug 28 '15 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\$ – Martin Ender Aug 28 '15 at 19:34
  • 7
    \$\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\$ – Martin Ender Aug 29 '15 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 May 20 '18 at 10:20

759 Answers 759

5
\$\begingroup\$

MY, 73 bytes

Here's the hex:

07 24 21 21 28 26
0A 24 21 28 26
0B 24 20 20 28 26
0B 24 20 20 28 26
0B 24 21 28 26
04 24 21 21 21 21 28 26
02 25 28 26
09 24 20 20 20 28 26
0B 24 21 28 26
07 25 21 21 28 26
0B 24 20 20 28 26
0A 24 28 26
02 25 21 28 26

I didn't want to update my old answer, because this one isn't just a simple one-byte solution that uses a builtin.

How it works: Outputs each character by using the few commands I have interpreted:

  • Number Literal: 0x00 - 0x0F
  • Minus 1: 0x20
  • Add 1: 0x21
  • Times 10: 0x24
  • Times 16: 0x25
  • Output: 0x26
  • Character value: 0x28
\$\endgroup\$
5
\$\begingroup\$

Chip, 174 166 106 97 bytes

94 bytes for the code + 3 bytes for the flag (-w) which allows execution without input.

!ZZZZZZZZZZZZt
|))))))x)))))f
|)xx)x-))xxxa
|)))))-))x))c
)))))x-))))g
)-))))-x)xd
    b e^b^e

Try it online!

Chip is a 2D language inspired by integrated circuits, input and output are broken down into individual bits which travel through gates and across wires.

Ungolfed (134 bytes):

!ZZZZZZZZZZZZt
xxxxxxxxxxxxxh
)))))xx)))))xg
x))))))x)))))f
xxxxxxx)x)xxxe
)x))))xx)x)xxd
x)))))x))x))xc
xxxx)xx)))xxxb
x)xx)xx))xxx)a

How the ungolfed version works:

This implementation encodes the target string Hello, World! as a bit matrix, somewhat reminiscent of core memory. The leftmost column of )'s and x's corresponds to H in the output, the rightmost column to !. The ) is an Or-gate (mapping to a 1 in the output), and the x is a wire crossing (mapping to a 0).

The first row is for timing, and the remaining rows are for each of the bits of the output (the row ending in h is the highest bit, and a is the lowest).

The timing behavior starts with the !. ! produces a single 1-cycle pulse at the beginning of execution. The line of Zs then control the left-to-right propagation of the signal at a rate of one element per cycle, each one corresponding to the transition between consecutive letters of the output. Each Z also sends a signal to the column below. At the end of the timing row is t, which terminates the program, preventing infinite output of null characters at the end.

In the first cycle, the first data column is powered. We see OR-gates ()) on the rows for bits d and g, turning them on; the remaining bits stay off because the wire crosses (x) won't propagate the signal from the top to the left. This gives us 01001000, which is H.

In the next cycle, only the second data column is powered. Rows a, c, f and g turn on much like the bits in the first cycle, and the remaining bits are off. This gives us 01100101, which is e.

This continues all the way across to the right, giving the remainder of the output.

Golfing it:

There's not a lot that could be done here, but there are a few things of note:

  • The h row is always off, so that can be eliminated.
  • Each row can be trimmed on both ends, removing unnecessary x's, so long as the timing signal can still be propagated downward to rows that need it below. This is why the rows are rearranged; to maximize the trimming that can occur.
  • The construct )a is equivalent to simply a, so long as the signal did not need to be propagated downward from the OR-gate.

All other changes are just mashing things around to save single bytes.

\$\endgroup\$
5
\$\begingroup\$

Pyramid Scheme, 857 bytes

  ^      ^      ^     ^      ^      ^      ^      ^      ^      ^      ^      ^      ^
 / \    / \    / \   / \    / \    / \    / \    / \    / \    / \    / \    / \    / \
/out\  /out\  /out\ /out\  /out\  /out\  /out\  /out\  /out\  /out\  /out\  /out\  /out\
-----^ -----^ -----^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^-----
    / \    / \    / \    / \    / \    / \    / \    / \    / \    / \    / \    / \
   /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\  /chr\
  ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^----- ^-----
 / \    / \    / \    / \    / \    / \    / \    / \    / \    / \    / \    / \
/72 \  /101\  /108\  /111\  /44 \  /32 \  /87 \  /111\  /114\  /108\  /100\  /33 \
-----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----

Try it online!

Wow. At least it's kinda clear how this works...

\$\endgroup\$
5
\$\begingroup\$

Windows Portable Executable (PE), 1175 bytes

By using the following Assembly code instead of C code (which inevitable imports unecessary libraries and whatnot), we can cut down the executable size from 261591 bytes (compiled C answer) to a measily 1536 bytes.

extern ExitProcess, GetStdHandle, WriteConsoleA

section .n
    msg db "Hello, World!",10

; <entry point>
Start:
    ; GetStdHandle(in A1)
    push -11           ; A1 - STD_OUTPUT_HANDLE
    call GetStdHandle  ; Puts in eax

    ; WriteConsole(in A1, in A2, in A3, out A4, reserved A5 )
    push 0             ; A5 - Don't care (reserved argument)
                       ; A4 - Don't care ("number of chars written")
    push 14            ; A3 - Length ("number of chars to write")
    push msg           ; A2 - String (buffer pointer)
    push eax           ; A1 - Console output handle (from GetStdHandle)
    call WriteConsoleA

    ; ExitProcess(in A1)
    push 0             ; A1 - Exit code
    call ExitProcess

However, that is still way too large. So I installed HxD, a hex editor, and went on to try and remove unecessary parts.

Apparently, Windows' executables are filled with padding (hex indication) for no apparent reason. So I removed the tailing block of zeroes at the end of the file, messed around a bit, and managed to cut it down to 1175 bytes. Here's the pastebin hexdump of the executable.

Unfortunately, at my every attempt to remove the other paddings (0x1A8-0x1FF, 0x22B-0x3FF), the program would simply not run. I've been doing this for a few days to no success. Thus, I'm posting this beaten, at the still staggering 1KB of size.

I am sure this can be golfed even further, so if anyone manages to cut down the size, feel free to edit this answer or perhaps even post another one.


As a bonus, this executable also works on DOS.

\$\endgroup\$
  • \$\begingroup\$ If anyone wants to try golfing this down some more, they may find this answer on SO and the material it references helpful. \$\endgroup\$ – 3D1T0R May 29 '18 at 19:53
  • 1
    \$\begingroup\$ github.com/pts/pts-tinype Some smaller Hello World .exes, not mine. I couldn't get the 268-byte ones to run at all, and the 402-byte one would only run with my antivirus shut off. \$\endgroup\$ – Nnnes Jul 23 '18 at 11:19
5
\$\begingroup\$

Magic Number, 174 bytes

0010000033001000010000100001080010000114001000011100100000870010000032001000004400100001110010000108001000010800100001010010000072006006006006006006006006006006006006006006

Magic Number is a simple human-writable stack-based esolang where the source code consists of a single positive integer. The decimal digits are read from most significant to least significant.

The only two commands used here are 0010xxxxxx, which pushes the non-negative integer xxxxxx onto the stack, and 006, which pops the stack and prints the character with that character code. The program pushes the numerical value of the characters in "Hello, World!" onto the stack in reverse order and prints them all. Branching is fairly expensive, so I feel this is probably optimal.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Martin Ender Aug 13 '17 at 17:35
5
\$\begingroup\$

Sad-Flak, 199+3 bytes = 202 bytes

3 bytes for the -A arg. This lang uses a "codepage", where ≤≥ are one byte each (that is, I have a thing that replaces ` and ~ with those chars and runs it)

32
({}≤()≥)
(≤()≥)
99
({}≤()≥)
((<>[≤()≥]))
7
({}≤()≥)
((<>))≤()≥
5
({}≤()≥)
(≤()≥)
109
({}≤()≥)
(<>)(≤()≥)
85
({}≤()≥)
(≤()≥)
30
({}≤()≥)
(≤()≥)
42
({}≤()≥)
({≤()≥})(({()}))({()})(())
70
({}≤()≥)
≤≥

Try it online!

Explanation:

The main idea behind this is that the way Sad-Flak works, you can easily get it to repeat a line a constant number of times.

in Sad-Flak, there is a line pointer. The line pointer starts at the beginning

-> 32
   ({}≤()≥)
   (≤()≥)
   99
   ({}≤()≥)
   ((<>[≤()≥]))
   7
   ({}≤()≥)
   ((<>))≤()≥
   5
   ({}≤()≥)
   (≤()≥)
   109
   ({}≤()≥)
   (<>)(≤()≥)
   85
   ({}≤()≥)
   (≤()≥)
   30
   ({}≤()≥)
   (≤()≥)
   42
   ({}≤()≥)
   ({≤()≥})(({()}))({()})(())
   70
   ({}≤()≥)
   ≤≥

however, the 32 is not actually a command. it is a simple way to express 32 blank lines. I could expand them for the demonstration, but then it would be unreadable. anyway.

So, the line pointer points at the first of 32 blank lines. When the line pointer points at a non-blank line, it will execute that line. when the line pointer points at a blank line, it will execute the first non-blank line after that line. that means we execute ({}≤()≥). What does this line do? This lang is a brainflak derivative, btw, so some of the brackets do the same thing, but not all

(        push...
 {}      pop off the main stack and evaluate to that value, plus
   ≤     jump by the amount inside, evaluate to that value for the purpose of other commands
    ()   1
      ≥
       )

so, this pops off the stack, adds one to it while jumping one forward, then pushes back on the stack. What is jumping? why are we jumping in the middle of a line?

Jumping in Sad-Flak is rather different to most other langs. Jumping does not take immediate effect, but rather moves the line pointer. when the line pointer is moved, nothing happens until the current line is finished executing. when it is finished, we see which line the line pointer points at, and execute that. If the line pointer didn't get moved, the same line gets executed again, and again, until it gets moved. however, all lines in this program either are blank, or they jump or halt. So, this line moves the line pointer one forward and increments top of stack.

What is the line pointer pointing at now? it's still on a blank line, so it does the same thing again, and again, until it gets to the line that it keeps executing

   32
-> ({}≤()≥)
   (≤()≥)
   99
   ({}≤()≥)
   ((<>[≤()≥]))
   7
   ({}≤()≥)
   ((<>))≤()≥
   5
   ({}≤()≥)
   (≤()≥)
   109
   ({}≤()≥)
   (<>)(≤()≥)
   85
   ({}≤()≥)
   (≤()≥)
   30
   ({}≤()≥)
   (≤()≥)
   42
   ({}≤()≥)
   ({≤()≥})(({()}))({()})(())
   70
   ({}≤()≥)
   ≤≥

Then, it executes it one last time, before moving to the next line. this end up with the charcode of ! on the stack (32 blanks + 1 actual line)

   32
   ({}≤()≥)
-> (≤()≥)
   99
   ({}≤()≥)
   ((<>[≤()≥]))
   7
   ({}≤()≥)
   ((<>))≤()≥
   5
   ({}≤()≥)
   (≤()≥)
   109
   ({}≤()≥)
   (<>)(≤()≥)
   85
   ({}≤()≥)
   (≤()≥)
   30
   ({}≤()≥)
   (≤()≥)
   42
   ({}≤()≥)
   ({≤()≥})(({()}))({()})(())
   70
   ({}≤()≥)
   ≤≥

this line ((≤()≥)) pushes a new 1 to the stack, and moves the line pointer one forward, onto a new blank line, to do basically the same thing as it did before. however it puts charcode of e. and also the next line is this: ((<>[≤()≥])). What is this complex line? well:

((        push twice...
  <>      value popped from stack, and pushed onto the offstack for later retrieval
    [     minus ...
     ≤    (jump but eval to the argument still)
      ()  1
        ≥
         ]
          ))

so, this pops the e off the stack, and replaces it with two ds, while leaving an e on the off stack for later retrieval, and also jumping the line pointer to the next line. we have two, because one will be changed into l, because it saves bytes from pushing a 1 and incrementing it up to the next letter. we don't do this for all of them because it also cost bytes popping and pushing back onto the stack, as well as fitting the jump in there.

from now on, I'm skipping the blank lines and the increment top of stack lines, because this explanation is long enough already.

after adding 8 to yield l

((          push twice...
  <>        a value popped from stack, also pushed to offstack
    ))
      ≤     jump ...
       ()   1
         ≥

add 6 to yield r: this one again: (≤()≥) new value at 111 (o):

(           push...
 <>         popped value, also pushed to offstack.
   )
    (       push...
     ≤      (jump and eval to same as...)
      ()    1
        ≥
         )

so this pushes to the off stack while keeping it on the stack, and pushing another 1 on the stack.

new 87 (W): this again: (≤()≥)

new 32 (space): same again: (≤()≥)

new 44 (,): ({≤()≥})(({()}))({()})(()) woah, what is that? put simply, it is just pushing onto the main stack what we pushed on to the offstack, then a 1 to make into a H:

(             push...
 {            pop from the off stack, evaluate to that multiplied by...
  ≤           jump and eval to...
   ()         1
     ≥
      }
       )         this pushes o

        ((         push twice...
          {        multiply an offstack popped value by...
           ()      1
             }
              ))     this pushes l twice

                (        push...   
                 {       offstack popped value times...
                  ()     1 
                    }
                     )      this pushes e

                      (    push...
                       ()  1
                         )

new 72 (H): ≤≥: this is the halt command and it stops the program

That pushed !dlroW ,olleH char codes, which then gets printed, but backwards because it is a stack. "Hello, World!"

\$\endgroup\$
5
+50
\$\begingroup\$

Pain-Flak, 152 bytes

)))))}{}{)))}{))(}{((((])][][][([(])()()([((]][[()()()(])}{][][)][(][([())(]][][][][][[))(]][[)][][)][][][][))(}{}{))))(}{)}{)}{))()()()((((((((((((}><{

This is a trivial modification of @HeebyJeebyMan's “Hello, World!” in Brain-Flak. They also discovered a slightly different solution with the same length shortly before I golfed mine down to this byte count.

Try it online!

How it works

Pain-Flak is transpiled to Brain-Flak as follows.

  • Let the Pain-Flak source code be S.
  • Transliterate S, replacing all opening brackets with their closing counterparts and viceversa. Call the result T.
  • Reverse S character by character. Call the result R.
  • The Brain-Flak source code is T || R, where || symbolizes concatenation.

For the Pain-Flak program in this answer, transpilation yields the following Brain-Flak program.

((((({}{}((({}((){}))))[([][][])])[()()()]))[[]])()()()[({}[][]([])[])])(()[[][][][][]](()[[]]([][]([][][][]((){}{}((((){}({}({}(()()()())))))))))))
{<>}
{<>}
(((((((((((()()()()){}){}){}()))){}{}())[][][][])[][])[[]]())[[][][][][]]())([([]([])[][]{})]()()()([[]](([()()()]([([][][])](((({}()){}))){}{})))))

Newlines have been inserted for "readability". The programs works as follows.

  • Line 1 pushes garbage on the first stack.

  • {<>} on line 2 switches stacks until the top of the stack is non-zero.

    This switches to the second stack.

  • {<>} does the same. Since the top of the second stack is 0, we stay on the second stack.

  • Line 4 is just @HeebyJeebyMan's “Hello, World!” in Brain-Flak, which never switches stacks and is, therefore, unaffected by the garbage on the first stack.

\$\endgroup\$
  • \$\begingroup\$ You care if i use the pain-flak description for my readme? \$\endgroup\$ – Christopher Jan 21 '18 at 0:17
  • \$\begingroup\$ @Christopher2EZ4RTZ Go ahead. :) \$\endgroup\$ – Dennis Jan 21 '18 at 0:19
5
\$\begingroup\$

Brain-Flak, 144 138 bytes

((((((((((((()()){}){}){}){}()))){}{}())([][]){})[][])[[]]())[((()[]){}){}])([()[]](([]([](([][]([](()[][]){})))[]{}[])[[]])))(([][][]){})

Try it online!

The product of my code from the Text to Brain-Flak challenge. Beats the previous answer by 4 bytes! Wheat Wizard has since updated to beat mine by 2. And my code has produced a 140 byte solution (which I've golfed a further 2 bytes off).

Explanation coming as soon as I understand it myself...

How It Works:

Note that Brain-Flak is a stack based language which outputs the stack on exit. This means the text has to pushed to the stack in reverse.

((((((((((((()()){}){}){}){}()))){}{}())([][]){})[][])[[]]())[((()[]){}){}])

This first part pushes "World!". This part is actually near identical to Wheat Wizard's answer, and has the same byte count.

( Pushing "W"
 ( "o"
  ( "r"
   ( "l"
    ( "d"
     ( "!"
      (((((
           (()()) Push 2
          {}) Pop the 2 to push 4
         {}) Pop the 4 to push 8
        {}) Pop the 8 to push 16
       {}()) Pop the 16 and create a 1 to push 33 ("!")
      )){}{}()) Create two copies of 33 and pop them to push 99 and a 1 to push 100 ("d")
      ([][]) Push the stack height (2) twice to the stack
     {}) Pop the 4 and push 8 + 100 = 108, ("l")
    [][] Add the stack height (3) twice to the current value
   ) Push 108 + 3*2 = 114 ("r")
  [[]]() Add negative stack height (4) and 1 to the current value
 ) Push 114 + (-4) + 1 = 111 ("o")
[ Subtract
 (
  (()[]) Push stack height (5) + 1
 {}) Pop the 6 to create 12
 {} Pop the 12 to create 24
]) Push 111 - 24 = 87 ("W")

This part pushes "ello, "

([()[]](([]([](([][]([](()[][]){})))[]{}[])[[]])))

( "e"
 [()[]] Save negative stack height (6) and 1 for later (-7)
 ( "l"
  ( "l"
   [] Save stack height (6) for later
   ( "o"
    [] Save stack height (6) again
    (( ","
      [][] Save stack height (6) twice (12)
      ( " "
       [] Save stack height (6)
       (()[][]){} Push 1 + stack height (6)*2 = 13 and double it = 26
      ) 26 + 6 = 32 (" ")
     ) 32 + 12 = 44 (",")
    )[]{}[] Add the stack height (9), pop the 44 and add the stack height again (8)
   ) 44 + 9 + 44 + 8 + 6 (saved) = 111 ("o")
  [[]] Subtract stack height (9)
 )) Push 111 - 9 + 6 (saved) = 108 ("l") twice
) Push 107 - 7 = 100 ("e")

And finally (([][][]){}) pushes "H" by adding the stack height (12) three times and doubling it.

\$\endgroup\$
5
\$\begingroup\$

Inform 7 + C by G, 36 bytes

Include C by G.Z:say "Hello, World!"

This code requires at least version 1/150829 of the code golfing extension.

\$\endgroup\$
  • 3
    \$\begingroup\$ I got rid of my old version. \$\endgroup\$ – Lynn Aug 29 '15 at 5:20
  • \$\begingroup\$ Please change the language name to "Inform 7 + C by G", since you're using a library \$\endgroup\$ – ASCII-only Apr 20 '18 at 1:22
  • \$\begingroup\$ @ASCII-only As the cost of the library is included I don't think that's necessary. \$\endgroup\$ – curiousdannii Apr 20 '18 at 1:34
  • \$\begingroup\$ @curiousdannii nope, it's still necessary (at least for libraries that don't come with the standard distribution) \$\endgroup\$ – ASCII-only Apr 20 '18 at 2:48
5
\$\begingroup\$

Whirl, 955 733 bytes

-~200 bytes using implicit modulo when output magic - I haven't checked anywhere close to all the simple possibilities, so this might be very suboptimal.

It might be possible to use memory/the operations wheel value as extra storage to make things shorter, but all approaches I've tried using those are not golfier than the naive one

1100001110010001111100110000000000000100000100000100000110000010000100100010001000000000000111110001111000111110001111000000000000011110000011100100011001111110001110011111000000000000000000000000000100100110000001111110001110011111000000000001001000100010000000000001111100000111110001001000110001000111110000011110000000000000000010001001100111111000100111110011000000000000000000000000010000011000000000110010001100010000000000011111000001111000000000000000000111110001111000111110001111000001001001100111111000111001111100000000000100100111001111110001111001111100000000000000000000000111100000111001000111001111110001111001111100000000000000000000000000000001111000001110010010001000000000000000000000000111110000011111000100100

Try it online!

Readable:

1 _
: ; _ + _ + _ + _ : _ + _ : _ * _ + _ : .
      + _ + _ + _ + : - _ + _ + _ + _ - _ : . _ :
      + _ + _ + _ + _ + _ + _ + _ : . _ . _ :
      + _ + _ + _ : .
      + _ + _ + _ + : + _ : .
      * _ - _ + _ + _ + _ + _ : . _
: ; _ + _ + _ + _ + _ + _ + _ : _ * _ * _ : .
      * _ * _ * _ - _ + _ + _ + _ + _ + : - _ + _ : . _ :
      + _ + _ + _ : . - :
      + _ + _ + _ + _ + _ + _ - _ : . - :
      + _ + _ + _ + _ + _ + _ + _ + _ - _ : .
      + _ + _ + _ + _ + _ + _ + : + _ : .

Every command switches operation wheels, starting from the operation wheel. Note that the cost depends on the current and previous command of the wheel, which is why there are so many no-ops.

Each character is on its own line, except for the two ls in a row. Some constructs used here are:

  • : ; - load the 1 from operation value into math value
  • _ + - add memory to math value - this can be used for e.g. repeated additions to emulate multiplications
  • _ * - square. This is used for H since 72 = 8 * 8 + 8
  • : . _ - store math value to memory, output, switch back to math wheel

Lines ending with : indicate the 1 from the operation wheel is being loaded, but the math value is not being overwritten. This is useful when consecutive characters are close in character codes.

Operation wheel commands

  • 1 - set (operation) value to 1
  • : - store value into memory. In this program it's always 1
  • . - output chr(memory)

Math wheel commands

  • + - add memory to (math) value - this is different to operation value
  • * - multiply memory with value
  • - - negate value - this is the only way to subtract
  • ; - load memory into value
  • : - store value into memory

See the language page for descriptions of unused commands

Try it online!

\$\endgroup\$
  • \$\begingroup\$ :| this is shorter than the all-caps no-punctuation one here (official website). is everyone bad at golfing or do i just have no life? also i have absolutely no clue how to contact the author \$\endgroup\$ – ASCII-only May 6 '18 at 5:08
5
\$\begingroup\$

Logo (programming language) - 20 bytes

PRINT [Hello, World!]

Or even more exciting version:

to helloworld
 hideturtle
 fd 20 left 180
 fd 40 left 180
 fd 20 right 90
 fd 20 left 90
 fd 20 left 180
 fd 40 left 90
 fd 20 left 90
 fd 20 right 90
 fd 20 right 90
 fd 10 right 90
 fd 20 left 90
 fd 10 left 90
 fd 30 left 90
 fd 40 left 180
 fd 40 left 90
 fd 20 left 90
 fd 40 left 180
 fd 40 left 90
 fd 40 left 90
 fd 20 left 90
 fd 20 left 90
 fd 20 left 90
 fd 60 left 90
 fd 40 left 180
 fd 40 left 90
 fd 20 left 90
 fd 20 left 180
 fd 20 left 90
 fd 20 left 90
 fd 40 left 180
 fd 40 left 90
 fd 40 left 90
 fd 20 left 90
 fd 20 left 90
 fd 20 left 90
 fd 40 left 90
 fd 20 right 90
 fd 20 right 90
 fd 5  left 90  
 fd 5  left 90  
 fd 25 left 180
 fd 40 left 90
 fd 40 left 90
 fd 20 left 90
 fd 20 left 90
 fd 20 left 90
 fd 20 left 90
 fd 40 left 180
 fd 40
end

lt 90 pu fd 200 pd rt 90 helloworld 

Output:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! This is code golf, so you should make sure that your answer is as short as possible. I don't know Logo, but it seems the HELLO is an arbitrary identifier, so you can probably shorten it and maybe it's also possible to get rid of some of that whitespace? Also, please use the required spelling Hello, World! and include the byte count of the code in your answer so that people can easily see its score. \$\endgroup\$ – Martin Ender Apr 10 '18 at 15:04
  • \$\begingroup\$ First-timer here. Cool, thanks. \$\endgroup\$ – Artur Kędzior Apr 10 '18 at 15:09
  • 2
    \$\begingroup\$ Hmm. I think you should stop drawing in between letters \$\endgroup\$ – ASCII-only May 18 '18 at 10:02
5
\$\begingroup\$

Symbolic Python, 175 157 147 136 bytes

_=-~(_==_)
_*=_-~_
__=_*_+~-~-_
_=('%'+`''`[~_/_])*-~-~_%(~-_*~-~-_,_*_+_/_,__,__,_*_-~_,',',' ',__-_+~_,_*_-~_,`_==_`[_/_],__,_*_)+'!'

Try it online!

I'm not sure this is optimal, but it sure was fun.

Explanation:

_=-~(_==_)           # Set _ to 2
_*=_-~_              # Set _ to 2*(2+2+1) = 10
__=_*_+~-~-_         # Set __ to 10*10+(10-1-1) = 108
_=                   # Set _ to
  ('%'+`''`[~_/_])      # %c, where c is coming from the character \x0c
  *-~-~_                # Repeated 12 times
  %(...                 # Then format into that format string
  ~-_*~-~-_,              # (10-1)*(10-1-1) = 72  = 'H'
  _*_+_/_,                # 10*10+1         = 101 = 'e'
  __,                     #                   108 = 'l'
  __,                     #                   108 = 'l'
  _*_-~_,                 # 10*10+10+1      = 111 = 'o'
  ',',                    #                         ','
  ' ',                    #                         ' '
  __-_+~_,                # 108-10-(10+1)   = 87  = 'W'
  _*_-~_,                 # 10*10+10+1      = 111 = 'o'
  `_==_`[_/_],            # second letter of True = 'r'
  __,                     #                   108 = 'l'
  _*_                     # 10*10           = 100 = 'd'
)+'!'                   # Then add the last char    '!'
                     # And implicitly print _
\$\endgroup\$
5
\$\begingroup\$

whenyouaccidentallylose100endorsementsinnationstates -  900   761   728   552  260 bytes

20280782166
114
fff#dff#dfffff#dfffffffffff#dfffffffffffffff#dffffffffffffffffffffffffffffffffff#dfffffffff#dfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff#dffffffffffffffffffffffffff#dfffffffffffffffffff#dffff#dffffffffff#dfffffffffff#d

Try it online!

Golfed down to 761 bytes by increasing the brute-forcer to seeds up to 9999, instead of 999

Golfed down to 728 bytes by increasing the brute-forcer to seeds up to 99999, instead of 9999

Golfed down to 552 bytes by increasing the brute-forcer to seeds up to 999999, instead of 99999

Golfed down to 260 bytes with the help of @ASCII_only

\$\endgroup\$
  • \$\begingroup\$ I'm very curious as to what the inspiration for this languages name is. \$\endgroup\$ – Gabriel Mills Feb 6 at 2:38
  • 2
    \$\begingroup\$ @GabrielMills Explained here to Dennis \$\endgroup\$ – MilkyWay90 Feb 6 at 2:42
4
\$\begingroup\$

unc, 38 bytes

ZNVa[]<<chgf[L'uRYYb~ JbeYQ#']:if 5:>>
\$\endgroup\$
4
\$\begingroup\$

Scala, 22 bytes

print("Hello, World!")

scala can run "scala scripts" which are not full program. you can save the above to a file and execute in the shell scala file.scala, and it will execute (shortcut without saving a file: scala -e 'print("Hello, World!")').

a full ordinary scala program that prints hello world:

object H extends App{print("Hello, World!")}
\$\endgroup\$
4
\$\begingroup\$

Nim, 20 19 bytes

echo"Hello, World!"

Saved one byte thanks to sp3000!

\$\endgroup\$
  • \$\begingroup\$ You can drop the space in between for the first one, I think :) \$\endgroup\$ – Sp3000 Aug 28 '15 at 15:09
  • \$\begingroup\$ Indeed, saved me one byte! \$\endgroup\$ – kvill Aug 28 '15 at 15:18
4
\$\begingroup\$

Emily, 22 bytes

println"Hello, World!"

This is a nice little language I stumbled upon recently.

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

Applescript, 15 bytes

"Hello, World!"

Normally a fairly verbose language, for this one this is all that is required.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's nice to see these verbose languages -- Applescript, PHP, PowerShell, etc. -- getting the better of lots of other languages for once. :) \$\endgroup\$ – AdmBorkBork Aug 28 '15 at 15:53
  • \$\begingroup\$ @TimmyD That doesn't mean that they are good languages. It's just that they are better at some things. \$\endgroup\$ – georgeunix Aug 28 '15 at 16:53
  • 1
    \$\begingroup\$ @georgeunix Oh, without a doubt. Every language has its pluses and minuses. There are plenty of things I'd change about PowerShell, but there's nothing else I'd rather use to script and config Exchange. Even if it had commands and functionality to do so, I don't think I could use Pyth or CJam or whatnot on a day-to-day basis instead. I was just meaning "It's nice to see non-golfing languages toward the top of the lowest-byte-count list for a change." \$\endgroup\$ – AdmBorkBork Aug 28 '15 at 17:06
  • \$\begingroup\$ I understand @TimmyD \$\endgroup\$ – georgeunix Aug 28 '15 at 17:07
4
\$\begingroup\$

VBScript, 28 Bytes

WScript.Echo "Hello, World!"

This (should be) the shortest that prints to STDOUT (i.e., the command prompt window), when executed via command prompt wscript .\hello-world.vbs or cscript //nologo .\hello-world.vbs (the //nologo is necessary to prevent copyright info from being displayed). If you just double-click it, you'll get a pop-up message box instead, similar to the shorter example, below, at 22 bytes:

MsgBox "Hello, World!"

When executed, this second option will output a pop-up message box displaying the text inside the quotes. Since it's not technically STDOUT, and we do have a legitimate way to display STDOUT, we'll count the longer version instead.

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

Ook!, 949 Bytes

Just translated one of the Brainfuck answers here.

Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook.
Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
Ook. Ook. Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook!
Ook! Ook! Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook?
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
Ook. Ook. Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook.
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook.
Ook! Ook! Ook? Ook! Ook! Ook! Ook? Ook. Ook. Ook.
Ook? Ook! Ook. Ook? Ook. Ook? Ook! Ook! Ook! Ook!
Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook.
Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook!
Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook! Ook.
Ook? Ook. Ook! Ook. Ook? Ook. Ook! Ook. Ook? Ook.
Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook.
Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
Ook! Ook! Ook! Ook. Ook? Ook. Ook! Ook! Ook! Ook.
Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook.
\$\endgroup\$
  • 2
    \$\begingroup\$ I always smile when I see this language. \$\endgroup\$ – AdmBorkBork Aug 28 '15 at 16:36
  • 2
    \$\begingroup\$ This might be a case of "If your language of choice is a trivial variant of another (potentially more popular) language...". The shortest Ook! program will always be the translation of the shortest BF program (because each BF character is converted to the same length in Ook). So if Ook has a separate answer it needs to be updated every time someone finds a new shortest Brainfuck solution. (Ultimately, it's your call though if Ook should remain separate.) \$\endgroup\$ – Martin Ender Aug 28 '15 at 17:06
  • 3
    \$\begingroup\$ I love reading the "Code" in a manner as if two people were talking to each other :) \$\endgroup\$ – MrPaulch Aug 29 '15 at 11:12
  • \$\begingroup\$ @MrPaulch I agree. The fact that first O is capitalized makes it sound like a fast Oh, okay with vocalized differences for punctuation in my mind. \$\endgroup\$ – mbomb007 Sep 1 '15 at 15:04
4
\$\begingroup\$

Octave, 19 bytes

disp"Hello, World!"
\$\endgroup\$
4
\$\begingroup\$

Vim, 17 bytes

iHello, World!{ESC}ZZ

Where {ESC} is a raw escape byte \x1b.

This will switch to insert mode (i), write Hello, World!, leave it (ESC), and save+quit (ZZ). An environment like vimgolf or anarchy golf has to do the output part for you, as Vim is, of course, just a text editor.

\$\endgroup\$
  • \$\begingroup\$ @LegionMammal978 the other seems to be Vimscript mislabelled as Vim. \$\endgroup\$ – primo Feb 26 '16 at 18:33
  • 3
    \$\begingroup\$ I think generally the standard is that vim solutions don't have to save and quit, they can just display the text onscreen at the end. (That's what mine have all done). This would allow you to take 3 bytes off. \$\endgroup\$ – DJMcMayhem Jun 29 '16 at 17:33
  • \$\begingroup\$ Way longer and wrong output, but more interesting: :h_4<CR>/"H<CR>ly2wZZp \$\endgroup\$ – BlackCap Oct 12 '17 at 19:22
4
\$\begingroup\$

TI-BASIC, 22 bytes

"Hello, World!

Note that the lowercase letters are 2 bytes each.

\$\endgroup\$
  • 4
    \$\begingroup\$ I don't think the initial : is really part of the program, so I think this has a score of 22. \$\endgroup\$ – Ypnypn Aug 28 '15 at 16:06
  • \$\begingroup\$ @Ypnypn I'll take your word on it :) \$\endgroup\$ – TheNumberOne Aug 28 '15 at 18:45
4
\$\begingroup\$

PARI/GP, 22 bytes

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

4, 117 bytes

3.6000160103602136033260433605446067260787008070200908000120902111120111011015065095105105115055035075115125105085044

How it works

Generating characters with a code point below 100 is straightforward.

I've managed to create the others (derol) with three assignments and five additions/subtractions, which I believe is optimal.

3.            Begin the program.
  6 00 01     Set cell[ 0] to 1.
  6 01 03     Set cell[ 1] to 3.
  6 02 13     Set cell[ 2] to 13.
  6 03 32     Set cell[ 3] to 32 = ' '.
  6 04 33     Set cell[ 4] to 33 = '!'.
  6 05 44     Set cell[ 5] to 44 = ','.
  6 06 72     Set cell[ 6] to 72 = 'H'.
  6 07 87     Set cell[ 7] to 87 = 'W'.
  0 08 07 02  Set cell[ 8] to cell[ 7] + cell[2] =  87 + 13 = 100 = 'd'.
  0 09 08 00  Set cell[ 9] to cell[ 8] + cell[0] = 100 +  1 = 101 = 'e'.
  0 12 09 02  Set cell[12] to cell[ 9] + cell[2] = 101 + 13 = 114 = 'r'.
  1 11 12 01  Set cell[11] to cell[12] - cell[1] = 114 -  3 = 111 = 'o'.
  1 10 11 01  Set cell[10] to cell[11] + cell[1] = 111 -  3 = 108 = 'l'.
  5 06        Print cell[ 6] = 'H'.
  5 09        Print cell[ 9] = 'e'.
  5 10        Print cell[10] = 'l'.
  5 10        Print cell[10] = 'l'.
  5 11        Print cell[11] = 'o'.
  5 05        Print cell[ 5] = ','.
  5 03        Print cell[ 3] = ' '.
  5 07        Print cell[ 7] = 'W'.
  5 11        Print cell[11] = 'o'.
  5 12        Print cell[12] = 'r'.
  5 10        Print cell[10] = 'l'.
  5 08        Print cell[ 8] = 'd'.
  5 04        Print cell[ 4] = '!'.
4             End the program.
\$\endgroup\$
4
\$\begingroup\$

Var'aQ, 20 bytes

"Hello, World!" cha'

Var'aQ nIv rur Hol. 'oH rut lo' jIH ngaj-ghItlh.

Note: ghu'vam laH mugh jIH vaj DaneH'a'.

\$\endgroup\$
  • \$\begingroup\$ mughwI' vItu' 'oHbe' majQa'. \$\endgroup\$ – mbomb007 Sep 1 '15 at 14:48
  • \$\begingroup\$ @mbomb007 Qo', jIHvaD pIch, bing pIch \$\endgroup\$ – Beta Decay Sep 1 '15 at 14:51
  • \$\begingroup\$ What language is this? \$\endgroup\$ – LegionMammal978 Sep 28 '15 at 1:00
  • 1
    \$\begingroup\$ @LegionMammal978 Klingon :) \$\endgroup\$ – Beta Decay Sep 28 '15 at 5:52
4
\$\begingroup\$

Q, 16 bytes

1"Hello, World!"

Just Y to go and we have the alphabet :)

Bit of a late update, but thanks to Mauris, we now have at least one language for every letter of the alphabet :D

Thanks @AaronDavies

\$\endgroup\$
  • 1
    \$\begingroup\$ Not quite the requested output. I think you want 1"Hello, World!"; (doesn't include the trailing newline; to add one, change the 1 to a -1). Note, also valid for k. \$\endgroup\$ – Aaron Davies Aug 29 '15 at 23:19
4
\$\begingroup\$

123, 282 267 bytes

22221121121112112222222211211112111211211222222221121121133121121312121122222222111211213
31211213122222222111211332113312112222221112112331123322222221111211111211222221111211211
22222222112111112112112112222222111112112112112222213312112131222222221121113321133121121

The newlines are only for cosmetic purposes. I'm fairly sure that this is not optimal.

Here is a slightly more readable (and also runnable) version:

H 22221121121112112
e 2222222112111121112112112
l 22222221121121133121121312
l 12112
o 22222221112112133121121312
, 2222222111211332113312112
  2222211121123311233
W 222222211112111112112
o 222211112112112
r 2222222112111112112112112
l 222222111112112112112
d 2222133121121312
! 2222222112111332113312112
1

I started out by constructing an optimal linear code (i.e. one which doesn't use 3s which allow for loop). That is quite simple: for each character, determine which bytes to flip from the last one. Move to the right-most character that has to be flipped (with a series of 2s), then move back to the left with 1 for each byte that has to be flipped and 121 for each byte that shouldn't be flipped. Finally move to the writing index -2 and print the character with 21. Repeat. At the very end, move to index -1 with a trailing 1 in order for the program to terminate.

This jumble of 1s and 2s was generated with this CJam script, which you can run online here:

0c"Hello, World!"+2ew::^{
_{2b8Ue[1a/W<1a*_,'2*'1@W%{'1"121"?}/"12"}{;"12112"}?
}/
'1

Then I removed some repetition of ones and twos by inserting loops by hand. 3 works as follows: if the instruction pointer is to the left of index 0, skip the 3. Otherwise, jump to the previous 3 if the current bit is 1 or jump ahead to the next 3 if the bit is 0. So simple loops, repeating a code segment x can be constructed as 33x33 or 33x3 (depending on whether the termination condition is "current bit is zero" or "moved to a negative index"). Then I started enumerating some relevant simple loops and when they are applicable. I've been using these loops only when moving back through the bits to change one character code to the next. If we can use a loop here depends both on the current state of a bit a and the target state b. I'll be denoting this combined state of each position as [a b]. Now here are the relevant loops and the required position patterns in a regex-like syntax:

121:    (^|[0 0]|[0 1]) ([1 1])+ [0 0]
112:    (^|[1 1]) ([0 0])+ ([0 1]|[1 1])
211:    ([0 0]|[0 1]) ([1 1])+ [0 0] ([0 0]|[1 1])
121121: ([0 0]|[0 1]) ([1 1] ([1 1]|[0 0]))+ [0 0]

Listing out the combined states for each character, we can annotate the potential loops and how many bytes they'll save (each ___ annotates the character above; sometimes multiple loops are possible):

H [[0 0] [0 1] [0 0] [0 0] [0 1] [0 0] [0 0] [0 0]]
e [[0 0] [1 1] [0 1] [0 0] [1 0] [0 1] [0 0] [0 1]]
l [[0 0] [1 1] [1 1] [0 0] [0 1] [1 1] [0 0] [1 0]]
        __________________121 -2
  ________________________121121 -3
l [[0 0] [1 1] [1 1] [0 0] [1 1] [1 1] [0 0] [0 0]]
o [[0 0] [1 1] [1 1] [0 0] [1 1] [1 1] [0 1] [0 1]]
        __________________121 -2
              __________________211 -2
  ________________________121121 -3
, [[0 0] [1 0] [1 1] [0 0] [1 1] [1 1] [1 0] [1 0]]
        ________________________211 -2
  [[0 0] [0 0] [1 1] [0 0] [1 0] [1 0] [0 0] [0 0]]
  ____________112 -2
W [[0 0] [0 1] [1 0] [0 1] [0 0] [0 1] [0 1] [0 1]]
o [[0 0] [1 1] [0 1] [1 0] [0 1] [1 1] [1 1] [1 1]]
r [[0 0] [1 1] [1 1] [0 1] [1 0] [1 0] [1 1] [1 0]]
l [[0 0] [1 1] [1 1] [1 0] [0 1] [0 1] [1 0] [0 0]]
d [[0 0] [1 1] [1 1] [0 0] [1 0] [1 1] [0 0] [0 0]]
        __________________121 -2
  ________________________121121 -3
! [[0 0] [1 0] [1 1] [0 0] [0 0] [1 0] [0 0] [0 1]]
        ________________________211 -2

Now I just picked the most profitable loop in each case and inserted it into the code.

I'm fairly certain that one could find a couple more loops that I've overlooked. But I also think that it's possible to find a significantly shorter solution that isn't based on anything a human would come up with. So far I have no idea how to efficiently search for such a solution automatically though, so I'll leave it at that for now.

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

Piet, 132 codels

On a 4x33 grid. On the last few commands I had to stretch to reach the end, meaning it could be golfed a little more (it probably fits on a 4x31 grid). Here it is, with codel size 10:

Piet code

I made it in a rectangular space to minimize the number of time I needed to flip the pointer. The stack is based on numbers 36 and 108 that are constantly being duplicated or rolled to produce the new letters.

Made and tested on PietDev.

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

Gol><>, 16 bytes

"!dlroW ,olleH"H

Try it online.

I've really enjoyed golfing in ><>, but unfortunately I've found that ><> lacks several features, e.g. STDIN integer input, which prevent it from being competitive in challenges it otherwise would be. Gol><> is designed to (hopefully) be an easier-to-use variation of ><>. I worked on it earlier in the year, around when the language showcase was happening, but took a break and only picked it up again recently. It's starting to stabilise, so I thought it'd be a good time to post a first answer.

Similarly to ><>, " is a string parsing operator which pushes chars one at a time until it reaches a closing ". H then halts the program, outputting the stack until it is empty.

Even without H, Gol><> can still output the stack in a relatively short way. l pushes the length of the stack, o outputs a char from the stack and R pops a number n, repeating the next instruction n times. Thus, an equivalent program would be

"!dlroW ,olleH"lRo;

where ; terminates the program with no output.

\$\endgroup\$
  • \$\begingroup\$ Another solution would be S"Hello, World!". \$\endgroup\$ – LegionMammal978 Nov 9 '15 at 12:39
  • \$\begingroup\$ @LegionMammal978 Indeed :) (although you'll need a ; at the end or it'll print forever) \$\endgroup\$ – Sp3000 Nov 9 '15 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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