Hello World! generator

-2

Often I need a simple Hello World! program to show some basic concepts of a programming language on my travels. As I usually travel only with light luggage I can't to carry a Hello World! program for each language. So a program that generates Hello World! programs in as many languages as possible would be a great help.

Task

Write a program or function that accepts a language as an input and outputs or returns the source code for program or function that accepts no input and outputs (not returns) Hello World!.

Input

The input defines in which language the Hello World! program should be generated. The input can be a number, a string, or whatever is the easiest for you. The input must only be used to select the language. You are not allowed to use the input as part of the output.

Please specify the valid inputs in your answer.

Output

The output can the return value, or be written to a file or STDOUT (or equivalent). It must full program of function in the language defined by the input. The resulting program/function must write Hello World! to STDOUT (or equivalent for the language). The output doesn't need to be exactly "Hello World!". Everything reasonably recognizable as Hello World! is acceptable. Eg. "HeLLo w0rlD1" would be an acceptable output. Also the resulting Hello World! string can be different for different languages. See bonus points section for more details.

Scoring

The program should work for as many languages as possible, and be as short as possible. Therefore the score is calculated by number of bytes / (number of supported languages - 1). Eg. an answer with 15 bytes and 3 supported languages would have a score of 7.5.

As usual with code-golf challenges lower scores are better.

Bonus points

  • You can subtract 10 percent from your score if the resulting Hello World! output for all supported languages is the same.
  • You can subtract and additional 10 percent from your score if the output for all supported languages is exactly Hello World!

raznagul

Posted 2017-01-18T11:27:40.850

Reputation: 424

Question was closed 2017-01-18T12:19:51.110

@Rod: I don't think it is a duplicate. The other question asks for polyglot, while my question asks for program, that output an other program. – raznagul – 2017-01-18T11:37:30.750

why a bonus for polyglots? – Destructible Lemon – 2017-01-18T11:49:57.747

2This challenge should be [tag:code-challenge], not [tag:code-golf], since the scoring is custom. Bonuses are generally discouraged. Also, the criteria of "Everything reasonably recognizable as Hello World!" is quite vague; challenges should have definitive criteria for valid submissions. – PurkkaKoodari – 2017-01-18T11:55:58.017

1Duplicate asks for a polyglot, your questions asks for a program that outputs that polyglot. I don't think putting a println("..") infront of any of the answers of the other post is any interesting (though, a valid solution). @raznagul – devRicher – 2017-01-18T11:57:59.180

Answers

4

PHP, 13 bytes, 9 languages, Score: 1.625*0.9^2 = 1.31625

Hello, World!

Explanation:

Hello, World! outputs Hello, World!. This can be used as input, and produce the same output in at least 9 languages.

Here's a list of languages this works for:

  1. Chaîne
  2. ///
  3. Lines
  4. if(j)invert()if(l)change()if(q)input()if(t)output(x);
  5. Carrot
  6. MicroSoft Windows HTA
  7. PHP
  8. pl
  9. Dogless
  10. Swap

This would give a fairly low score too, in Octave:

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

It prints print("Hello, World!") and should work in Perl, R, Ruby, Julia, Python 2, Python 3, Qbasic, Zsh/ksh, Cheddar among others.

Thanks to Dada for noticing I had capital instead of lower case P.

Stewie Griffin

Posted 2017-01-18T11:27:40.850

Reputation: 43 471

I think you can use the 0-byte program in Stuck to generate the program Hello, World! for all 10 languages ;-)

– ETHproductions – 2017-01-18T21:37:22.670

Haha :) Can't get a much lower score than that :) – Stewie Griffin – 2017-01-18T21:43:07.210