14
\$\begingroup\$

Produce a text file that prints "Hello World!" in as many programming languages as possible when compiled/interpreted, while also being as short as possible.

The score for your submission is calculated as C / 2 ^ ((L - 1) / 4), where "C" is the length of the text file in characters and "L" is the number of languages that the program is valid in. Lowest score wins, of course.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This question is similar to this other one, but in this case, you can share "Hello World" among some languages if you wish. \$\endgroup\$
    – Joe Z.
    Feb 15, 2013 at 18:52
  • \$\begingroup\$ Does it have to be a whole program or just a valid command? \$\endgroup\$ May 17, 2015 at 14:45

9 Answers 9

21
\$\begingroup\$
print("Hello World!")

Works in at least Julia, Perl, PHP, Python2, Python3, Qbasic, R, Ruby ...

\$\endgroup\$
13
  • 1
    \$\begingroup\$ It also works in R and Julia (and surely in many other languages). \$\endgroup\$ Feb 19, 2013 at 7:20
  • 2
    \$\begingroup\$ @jdstankosky, that exact code not works in PHP. pastebin.com/9x6HactK \$\endgroup\$
    – manatwork
    Mar 9, 2013 at 16:17
  • 1
    \$\begingroup\$ Kind of forcing the limits, but we can say it works in JavaScript too, as some command line interpreters provide print() function for outputting. pastebin.com/6fXtgFER \$\endgroup\$
    – manatwork
    Mar 9, 2013 at 18:14
  • 3
    \$\begingroup\$ works in lua too \$\endgroup\$
    – mniip
    Dec 31, 2013 at 1:54
  • 2
    \$\begingroup\$ @gnibbler, doesn't work in PHP without the opening tags. \$\endgroup\$
    – Tyzoid
    Dec 31, 2013 at 3:10
14
\$\begingroup\$

JavaScript ES6, Oration, Vitsy, Minkolang score = 71.94703045766462

121 / 2^(3/4). Fun fact? I'm not trying to win, just to add as many languages as possible.

222 //X>"!dlroW olleH"Z 
shush=0
alert("Hello World!")
sorry=`
listen
capture Hello World!`
$$$
=` >###      .O$r"!"rXr<`

What Vitsy sees

"Well, I'm a 1D language, so... for now, only the first line counts."

222 //X>"!dlroW ,olleH"Z
222                      push three twos
    //                   divide twice
      X>                 drop the result and carry on
        "!dlroW ,olleH"Z standard Hello, World! program

Thanks for the cookie, Vitsy :3

What JavaScript ES6 sees

222 //X>"!dlroW ,olleH"Z

"Let's see... You put the number 222 and then put something in a comment. Alright, sure, I'll roll with that."

shush=0

"You made a variable. Noted."

alert("Hello, World!")

"Ah, I see where you're going with this. I'll display that."

sorry=`
listen
capture Hello, World!`

"Oo! A multiline string! Now we're talking, ES6 rulez, ES5 drools!"

(EOF)

"Well, I'm done. Peace out."

What Oration sees

222 //X>"!dlroW ,olleH"Z

"This wasn't on my notes...! Best not do anything."

shush=0
alert("Hello, World!")
sorry=`

"Oh, here's some extra notes."

listen

"Listen..."

capture Hello, World!`

"...Hello, World!"

(EOF)

"thinks Nothing more! Great, I'm done here. breathes deeply"

Minkolang explanation

(Too lazy to create narrative. Might do later, the code took a while.) Irrelevant code replaced with # or omitted. Also, added comments C ... C.

222 ###>"!dlroW olleH"# 
$$$  C this separates layers C
###>### #####.O$r"!"rXr<`

Layer 1, pt 1

222 ###>"!dlroW olleH"# 
222                      C push three 2s C
   _                     C space; fall to the next layer C

Layer 2, pt 1

###>### #####.O$r"!"rXr<`
   >                       C go this way C
       _                   C fall to the next (first) layer C

Layer 1, pt 2

222 ###>"!dlroW olleH"# 
       >"!dlroW olleH"   C go right and push those characters in that order C
                       _ C fall to the next layer C

Layer 2, pt 2

###>### #####.O$r"!"rXr<`
                       <  C starts here, going left C
                      r   C reverse stack C
                     X    C pop n (n = 2), and pop top n items on stack (2, 2) C
                    r     C reverse stack C
                 "!"      C push exclamation mark (for some reason, it's chopped off C
                r         C reverse stack C
              $O          C output stack as characters C
             .            C terminate program C
\$\endgroup\$
1
  • 4
    \$\begingroup\$ My child is proud of your submission. Here. Have a cookie. +1 \$\endgroup\$ Feb 2, 2016 at 23:23
9
\$\begingroup\$
'Hello World!'

Runs in several scripting languages, including PHP, GolfScript, APL, ...

\$\endgroup\$
5
  • \$\begingroup\$ Also AppleScript and Javascript :) \$\endgroup\$
    – tomsmeding
    Feb 21, 2013 at 19:03
  • \$\begingroup\$ Won't Javascript include the quotes? \$\endgroup\$
    – Joe Z.
    Feb 22, 2013 at 4:18
  • \$\begingroup\$ This works in PowerShell too. \$\endgroup\$
    – Iszi
    Nov 22, 2013 at 20:51
  • 1
    \$\begingroup\$ Works in all derivatives of H9+ except for FISHQ9+ too \$\endgroup\$
    – Tornado547
    Nov 28, 2017 at 20:36
  • \$\begingroup\$ Probably the best answer, If you run in python shells would work too \$\endgroup\$
    – Wasif
    Nov 15, 2020 at 3:17
9
\$\begingroup\$

Score of 0.84

H

Works in H9+ and HQ9+.

1 / 2 ^ ((2 - 1) / 4) = 0.84

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You forgot: HQ9++, HI9+, FISHQ9+, CHIQRSX9+. \$\endgroup\$
    – user75200
    Oct 27, 2017 at 17:36
  • \$\begingroup\$ @user75200 I'm guessing those weren't as popular back in 2013 \$\endgroup\$
    – Timtech
    Oct 28, 2017 at 2:51
1
\$\begingroup\$

CoffeeScript and CJam, 46/2^((2-1)/4)=38.68

e###
"Hello, World!"
e###alert "Hello, World!"
\$\endgroup\$
1
\$\begingroup\$

ES8, Japt, TeaScript, C#, C++, C, ESMin, score: ~8.8

main=_=>"Hello World!"();

ES8, TeaScript and Japt see "Hello World!".

\$\endgroup\$
5
  • \$\begingroup\$ It won't work in Hello due to extra characters. \$\endgroup\$
    – user75200
    Oct 26, 2017 at 7:03
  • \$\begingroup\$ I'm pretty sure a lot of these (HQ9, Hello, and variants) don't count because they're not "real" programming languages. \$\endgroup\$
    – KSmarts
    Nov 2, 2017 at 14:47
  • \$\begingroup\$ Yes they're. They're real languages. But they may or mayn't work. And Hello++ discards non-h characters. Hello++++ discards all not part of "Hello world!" \$\endgroup\$
    – user75200
    Nov 4, 2017 at 18:36
  • \$\begingroup\$ According to PPCG standards, they're not. \$\endgroup\$
    – KSmarts
    Nov 5, 2017 at 23:03
  • \$\begingroup\$ And there's no HQ9. \$\endgroup\$
    – user75200
    Nov 12, 2017 at 10:47
1
\$\begingroup\$

Madbrain and [insert most BF derivatives here], 272 227 bytes

Just posting for fun, not to win c:

956658555658
852224222254
************
c4993c839941
1****1**+**+
01cc70776ccc
g+11+g++*11
 c003 c3c00
 1gg* 1*1gg
 0  c 0c0
 g  1 g1g
    0  0
    g  g[-]+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++.>>.>.<<<.+++.------.<<-.>>>>+.

NOTE: There is no TIO for Madbrain, so you'll have to trust me on this one. I did, however, write an (admittedly not really well-written (but hey, at least it works!)) interpreter for Madbrain, which is on the esolangs wiki.

Explanation

Madbrain sees: (I wrote this code c:)

956658555658
852224222254
************
c4993c839941
1****1**+**+
01cc70776ccc
g+11+g++*11
 c003 c3c00
 1gg* 1*1gg
 0  c 0c0
 g  1 g1g
    0  0
    g  g

I admit, Madbrain reaches the BF code, but it doesn't do anything, so I didn't include it here.

Brainfuck (and a lot of BF derivatives) sees:

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

BF ignores everything that isn't ><+-.,[], so it ignores most of the Madbrain code. However, there are some +s in the Madbrain code (that's what the ++++++ is), so you need to add [-] after that which sets the current cell to 0.

The code after ++++++[-] is the code for printing Hello World!.

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

TI-BASIC and Pyth, 13/2^((2-1)/4)=10.93

"Hello World!

Note: Non-competing answer, as Pyth was created after this challenge was posted

\$\endgroup\$
2
  • \$\begingroup\$ Also works in ESMin, Japt, Teascript, O, etc. \$\endgroup\$ Feb 3, 2016 at 6:29
  • \$\begingroup\$ Feel free to write in any language you desire, it matters not when it was made. \$\endgroup\$
    – user75200
    Oct 29, 2017 at 17:54
0
\$\begingroup\$
puts "Hello world!"

Works in Ruby and Tcl

\$\endgroup\$

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.