The challenge is to create a program that solves any one of the HQ9+ problems while looking like another language.

Note: This is not a golf challenge.


  • The program must perform one of the following tasks when run.
    • Print "Hello, World!"
    • Print its entire source.
    • Print the lyrics to "99 Bottles of Beer on the Wall" (as seen here).
  • At first glance the program should look like another language.


  • Working program that satisfies the rules. +3
  • Bonus points if the "other language" can be run (syntax valid). +1
  • Even more points if the "other language" can do something useful. +3
  • Lots of bonus points for the program being valid (and useful) in even more languages. +5 for each language over 2.
  • 1
    \$\begingroup\$ How are they graded? You need an objective criterion. Check here: codegolf.stackexchange.com/help/on-topic \$\endgroup\$
    – MrZander
    Commented Nov 22, 2013 at 20:08
  • \$\begingroup\$ Okay, I'm adding a points system. \$\endgroup\$
    – Kevin Cox
    Commented Nov 22, 2013 at 20:11
  • 1
    \$\begingroup\$ So... you're looking for a polyglot? \$\endgroup\$
    – Iszi
    Commented Nov 22, 2013 at 20:45
  • \$\begingroup\$ Yes. But with emphasis on "hiding" the features of all but one language to an extent. \$\endgroup\$
    – Kevin Cox
    Commented Nov 22, 2013 at 20:51
  • 4
    \$\begingroup\$ print ("Hello, World"); by itself will run in a lot of languages \$\endgroup\$
    – marinus
    Commented Nov 24, 2013 at 16:58

13 Answers 13



Print 'Hello, World!' -- she said.

Looks like English.


Ruby + C + Whitespace.

This program is C but looks like (and runs as) Ruby. I also managed to throw some whitespace in there.

C prints its own source (not quite a quine unfortunately). Ruby prints 99 bottles of beer and whitespace says hello.

#include <stdio.h>  
#define def int          
#define beer main(int i){char b[1024];          
#define print(v) print(int v){            
#define end ;}                
#define if(x) fputs(b,stdout); fgets(b,1024,f); if(x){               
#define else ;} else{                       
#define puts                    
#define print        
#define open(fn) FILE *f = fopen(fn,"r");             
#define while(x) fgets(b,1024,f); while(!feof(f)){                      

def beer                
    # define beer      



    while ( i >= 0 )
        if ( i > 0 )
            print "#{i} bottle#{i==1&&''||'s'} of beer on the wall, "
            puts  "#{i} bottle#{i==1&&''||'s'} of beer."
            print "Take one down and pass it around, "
            puts  "#{i-1} bottle#{i==2&&''||'s'} of beer on the wall."
            puts "No more bottles of beer on the wall, no more bottles of beer."
            puts "Go to the store and buy some more, 99 bottles of beer on the wall."
        i -= 1

    return 0      


And since SO isn't very nice to ws here is a link.


Golfscript / HQ9+


A Golfscript quine that doubles as an HQ9+ program that prints the lyrics to 99 bottles of beer.

I know this isn't a golf challenge, but I couldn't resist the desire to answer this with one character.

  • 1
    \$\begingroup\$ And I was silly enough to assume HQ9+ couldn't look like another language :D \$\endgroup\$
    – Kevin Cox
    Commented Nov 23, 2013 at 15:04
  • 5
    \$\begingroup\$ Yes! And crazily it looks lie the number "9". \$\endgroup\$ Commented Nov 27, 2013 at 14:21
  • \$\begingroup\$ Also prints 9 in html but unfortunately that is not considered a quine. \$\endgroup\$ Commented Jun 2, 2023 at 13:34

Perl, 7 points

99 <?php
for($i='no more',$_="`\2l\";7hF'`-{9\17p\t\2ZY\14fE\25T\133J`\35l\"76~\x3";
99>${2}="$i bottle".(${$i+=1}<'))'?+s?:s:!'((').' of beer';
Take one down and pass it around, ${1}.

".ucfirst("${1}, ${2}.${3}"))${1}=$i||${2}?"${2} on the wall":'?;\'';
print substr("${1}, ${2}.${3}".
($_^"jE\3\2OXH2O\5\15\10M$_").", ${2} on the wall.",3,13*$i*$i);

This is a Perl program that prints Hello, World!.

Score breakdown:

  • Follows all rules: +3
  • Is valid syntax in another language: +1
  • Does something interesting in the other langauge: +3


Once you know what it does it might seem 'obvious' where it's hanging out, but this is a dupe.

The following:


will output:

Go to the store and buy some moreET[J`l"76~

JavaScript, 7 points

h='Hello, World!'


<b>Hello, World!</b><br>


This is my <i>awesome</i> Hello World page<br>


Look I can make images I'm so good at HTML:<br>
<img src='http://pieisgood.org/images/slice.jpg' alt='awwww you cannot see my amazing image' /><br>

These are the things this page has:<br>

I like random characters! That's what this page will finish with:<br>

When run in JavaScript, produces "Hello, World!"

When viewed as HTML, looks like this:



  • Working program that satisfies the rules +3
  • Other language syntax is valid +1
  • Other language does something useful (you can put any HTML you want in there) +3
  • \$\begingroup\$ Subtle! This assumes that the implementation evaluating it prints out the completion value of the last statement to stdout, though. \$\endgroup\$
    – FireFly
    Commented Nov 26, 2013 at 18:05
  • \$\begingroup\$ @FireFly yes, that's what eval and all consoles do. \$\endgroup\$
    – Doorknob
    Commented Nov 26, 2013 at 19:11
  • \$\begingroup\$ eval doesn't print it to stdout; it returns it as the result of the function call expression. But yeah, I'm just nitpicking; sorry. :p \$\endgroup\$
    – FireFly
    Commented Nov 26, 2013 at 19:25

The following prints "Hello,World" (and a random table) in HTML and "Hello, World!" in Whitespace.



#include <iostream>

#define print(a) int main() {std::cout << a << std::endl;}

print("Hello, World!")

Will run in Python (both 2.x and 3.x) and compile in C++ to print (with carriage return):

Hello, World!


JavaScript, 3p

$res = Array();
$ks  = Array("", "", "");

function convert($x) { return $x["toString"](36); }
for ($i=0; $i < 1000000; $i++) {
  this[convert($i)] = $i;

  if ($i == 626 || $i == 777 || $i == 865 || $i == 1176 || $i == 35761)
    $res[$res.length] = convert($i);

  if ($i == 381  || $i == 19145) $ks[0] += convert($i);
  if ($i == 19   || $i == 31775) $ks[1] += convert($i);
  if ($i == 1033 || $i == 27893) $ks[2] += convert($i);
this[$ks[0]]($res[$ks[1]]("")[$ks[2]](1)[$ks[1]](" "));


<h1>hi</h1>   /// heading
<p>lol</p>    /// content

Masquerades the output of a misconfigured web server, as (something that at first glance looks like) PHP+HTML mess.

This started out small but grew bigger as I tried to make it less obvious what it does (when evaluated as JS)... it might've become more obfuscated than the task intended, sorry about that. Anyway, the main thing I wanted to include was my trick for embedding (a subset of) HTML such that it's also valid JavaScript code, which is what you see at the end of the code.

Edit: oh, I should mention, when run in a website context the code alerts "hello world".

  • \$\begingroup\$ Aha I love the dollar sign vars. The javascript html is also really cool. \$\endgroup\$
    – Kevin Cox
    Commented Nov 27, 2013 at 1:27
  • \$\begingroup\$ Hehe, the trick with the javascript HTML is that < and > are comparisons, /.../ is a regex literal (hence the triple-slashes for comments..) and JS doesn't care one bit about the types. \$\endgroup\$
    – FireFly
    Commented Nov 27, 2013 at 6:49

PHP, HQ9+, Brainfuck and Bash (23 points, I think)

Looks like PHP, but...

Abuse of STDERR redirection and quotes.

what the >&_@ is a "<?php
//Boring, really ( ;[ ). This just prints Hello World!"
echo "Hello, World!"; //]&> are random characters that I like putting in"
?>" program?

This runs and does things in all the languages listed, but looks like (slightly weird) PHP code.

In Bash, it merely prints "Hello, World!" (creating junk files along the way).

In HQ9+, it prints Hello World a few times (once for every occurence of H or h).

In Brainfuck, it is a "cat program" - it reads from standard input and outputs its input to standard output (><,[.,]>>).

In PHP, it prints some text:

what the >&_@ is a "Hello, World!" program?

Bash Explanation

>&_@ is disguised as harmless text substituting a curse, but it is in fact a redirection of STDERR to the file _@, so that Bash doesn't complain that what is not a valid program. It also eats the is a <?php bit and the first comment.

The first comment has a quote at the end (the quotes are there to prevent <?php from being run). echo "Hello, World!"; runs normally in both languages. The next comment serves to hide another quote, and there is an output redirection from STDERR to the file are, to eat the message " //: Is a directory".

Since the closing ?> is in quotes, it doesn't get run, and gets eaten along with the second comment and the bit after it.


Python/PHP/Lua/Perl/Perl 6/Ruby/JavaScript/HQ9+ (37 points)

print("Hello, World!")

This looks like "Hello, World" in Python, but it's actually a quine written in PHP. It also works in JavaScript (SpiderMonkey), Lua, HQ9+, Perl, Perl 6 and Ruby, for bonus points.


JavaScript/Python 3/PHP/Lua/Brainfuck/bash

This looks like... Umm... Obfuscated PHP?

echo = --[[0] ] [0][0] //1#>/dev/null;echo Hello, World!;exit # ]]0
--[[0] ] [0][0] //1#<?php for ($i = 99; $i > 1;) { printf("%d bottles of beer on the wall, %d bottles of beer.\nTake one down and pass it around. %d bottle%s of beer on the wall.\n\n", $i, $i, --$i, ($i != 1 ? "s" : "")); } print("1 bottle of beer on the wall, 1 bottle of beer.\nTake on e down and pass it around. No more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more. 99 bottles of beer on the wall.\n"); die(); ?>
2//2; print("Hello world!"); exit();"""
console.log("Hello, World!");/*]]
f = io.open(arg[0])
  • If you run it in bash, JavaScript or Python it'll print "Hello, World!"
  • If you run it in Lua, it'll print the script's source code (if provided as the first argument to lua).
  • If you run it in PHP it'll print the lyrics of 99 bottles of beer
  • If you run it as Brainfuck, it'll work like cat.

Score: 27

  • Follows the rules: 3
  • Other language can run: 1
  • Does something useful: 3 (cat program)
  • Also works in JS/Python 3/Lua/bash: 20

I hope I'm not bending the rules too much :)


Java written in C++

#include <stdio.h>

typedef char* String;

class P{
    static void println(String s){

class S{
    P out;

int main()
    S System;
    System.out.println("Hello world!");
    return 0;

Score 3 points.

print `open(__file__).read()`, 1000 // len('''
/* Calculate code conciseness score for some random JavaScript */

function print() {
    console.log('Hello, world!');

<!--''') # ASCII submarine

This looks like Python 2, and runs as Python 2, printing its own source in Python string literal form, as well as a code conciseness score of some kind! When run as ES6, however, it prints “Hello, world!”.


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