Build a polyglot for Hello World

15

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.

Joe Z.

Posted 2013-02-15T18:47:30.547

Reputation: 30 589

Does it have to be a whole program or just a valid command? – ASCIIThenANSI – 2015-05-17T14:45:15.223

1

This question is similar to this other one, but in this case, you can share "Hello World" among some languages if you wish.

– Joe Z. – 2013-02-15T18:52:46.663

Answers

20

print("Hello World!")

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

gnibbler

Posted 2013-02-15T18:47:30.547

Reputation: 14 170

Works in Perl 6 too – Hotkeys – 2016-02-03T21:37:38.387

1It also works in R and Julia (and surely in many other languages). – Sven Hohenstein – 2013-02-19T07:20:20.200

works in PHP too – jdstankosky – 2013-03-08T14:39:32.963

This print() syntax is also valid in Transact-SQL. http://pastebin.com/is2mqRJC

– manatwork – 2013-03-09T16:03:54.060

2

@jdstankosky, that exact code not works in PHP. http://pastebin.com/9x6HactK

– manatwork – 2013-03-09T16:17:06.163

1

Kind of forcing the limits, but we can say it works in JavaScript too, as some command line interpreters provide print() function for outputting. http://pastebin.com/6fXtgFER

– manatwork – 2013-03-09T18:14:48.197

@manatwork Well, <?php print("Hello World!") ?> since you want to get specific, but I'm not counting the <?php ?> tags. – jdstankosky – 2013-03-11T20:32:12.463

Works in TI-Basic too. – Timtech – 2013-12-31T00:38:30.823

3works in lua too – mniip – 2013-12-31T01:54:46.010

2@gnibbler, doesn't work in PHP without the opening tags. – Tyzoid – 2013-12-31T03:10:59.147

Works in all derivatives of H9+ except for FISHQ9+ too – Tornado547 – 2017-11-28T20:36:22.183

Assuming it is valid in the 8 languages listed, the score is at most(as in numerically) 21/2^((8-1)/4)=6.2433373537642856 – Naruyoko – 2019-08-30T16:45:57.153

12

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

Conor O'Brien

Posted 2013-02-15T18:47:30.547

Reputation: 36 228

4My child is proud of your submission. Here. Have a cookie. +1 – Addison Crump – 2016-02-02T23:23:18.850

9

Score of 0.84

H

Works in H9+ and HQ9+.

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

Timtech

Posted 2013-02-15T18:47:30.547

Reputation: 12 038

1You forgot: HQ9++, HI9+, FISHQ9+, CHIQRSX9+. – user75200 – 2017-10-27T17:36:31.930

@user75200 I'm guessing those weren't as popular back in 2013 – Timtech – 2017-10-28T02:51:03.063

8

'Hello World!'

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

Howard

Posted 2013-02-15T18:47:30.547

Reputation: 23 109

Also AppleScript and Javascript :) – tomsmeding – 2013-02-21T19:03:44.870

Won't Javascript include the quotes? – Joe Z. – 2013-02-22T04:18:23.323

This works in PowerShell too. – Iszi – 2013-11-22T20:51:19.793

1Works in all derivatives of H9+ except for FISHQ9+ too – Tornado547 – 2017-11-28T20:36:58.683

1

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

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

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

user75200

Posted 2013-02-15T18:47:30.547

Reputation: 141

It won't work in Hello due to extra characters. – user75200 – 2017-10-26T07:03:48.243

I'm pretty sure a lot of these (HQ9, Hello, and variants) don't count because they're not "real" programming languages. – KSmarts – 2017-11-02T14:47:10.177

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!" – user75200 – 2017-11-04T18:36:30.863

According to PPCG standards, they're not.

– KSmarts – 2017-11-05T23:03:38.577

And there's no HQ9. – user75200 – 2017-11-12T10:47:33.710

1

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!.

Sagittarius

Posted 2013-02-15T18:47:30.547

Reputation: 169

1

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

e###
"Hello, World!"
e###alert "Hello, World!"

username.ak

Posted 2013-02-15T18:47:30.547

Reputation: 411

0

puts "Hello world!"

Works in Ruby and Tcl

Victor VosMottor thanks Monica

Posted 2013-02-15T18:47:30.547

Reputation: 275

0

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

Arcturus

Posted 2013-02-15T18:47:30.547

Reputation: 6 537

Also works in ESMin, Japt, Teascript, O, etc. – Mama Fun Roll – 2016-02-03T06:29:27.337

Feel free to write in any language you desire, it matters not when it was made. – user75200 – 2017-10-29T17:54:24.677