-2
\$\begingroup\$

This question already has an answer here:

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!
\$\endgroup\$

marked as duplicate by Rod, TuxCopter, Pietu1998, devRicher, george Jan 18 '17 at 12:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ @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. \$\endgroup\$ – raznagul Jan 18 '17 at 11:37
  • \$\begingroup\$ why a bonus for polyglots? \$\endgroup\$ – Destructible Lemon Jan 18 '17 at 11:49
  • 2
    \$\begingroup\$ This challenge should be code-challenge, not 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. \$\endgroup\$ – Pietu1998 Jan 18 '17 at 11:55
  • 1
    \$\begingroup\$ Duplicate 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 \$\endgroup\$ – devRicher Jan 18 '17 at 11:57
4
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I think you can use the 0-byte program in Stuck to generate the program Hello, World! for all 10 languages ;-) \$\endgroup\$ – ETHproductions Jan 18 '17 at 21:37
  • \$\begingroup\$ Haha :) Can't get a much lower score than that :) \$\endgroup\$ – Stewie Griffin Jan 18 '17 at 21:43

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