Hello World! (polyglot edition)

Sparked from a conversation I had with a friend and fellow programmer some odd hours ago, I decided it would be fun to try to make a program that would run in more than one language. Initially, I thought of Brainf*ck and C(++), but my friend suggested I add Whitespace to the mix too. As it turned out, I managed to throw in Python as well.

After some kind people in #esoteric@irc.freenode.net (I joined originally because it was my first foray into the madness that is Whitespace) told me that this is what is called a polyglot, they helped me shave the last fat off and this is the result. A 384 byte “Hello World!\n” that works in Brainf*ck, Whitespace, Python and C++. Not the worst thing I’ve spent a sleepless night on.

As for acknowledgements, I admit that the bf version was one I had lying around, and I don’t know if it was my own or someone else’s. I did the ws version myself because I couldn’t find a working version anywhere. I do owe thanks to coppro and immibis from #esoteric, they were most helpful in the final stages of the process.

UPDATE: reddit users mallardtheduck, isionous and youreameme have suggested further enhancements, which have resulted in shaving off a further 28  bytes, so here is an updated version weighing in at 356 bytes. Many thanks, reddit!

8 Responses to “Hello World! (polyglot edition)”

  1. Its… beautiful. :)

  2. RAJ says:

    Looks great :)

  3. Bob says:

    Works in Perl too. :-)

  4. Totally Sweet man

  5. @Bob
    Almost, but not quite – it doesn’t output a linebreak after the “Hello World!”.

  6. frangossauro says:

    Also works in Ruby.

  7. @frangossauro
    Same problem as with perl – it could be remedied by dropping support for python I suppose…

  8. Danny says:

    Removing the first line (“#include “cstdio”"), if possible, and adding a semicolon (“;”) after “print(“Hello World!”)” makes it work for JavaScript and Lua.

Leave a Reply