Ultimate Programming ChallengeA while ago, I posted a blog entry about the Ultimate Programming Challenge and as it was the blog's most popular article (I know a whole three people who have read it!), I thought I would make it into a separate page to try and rally up other people to join in too. So far I've got one extra addition of Befunge (thanks Rob) to my original program for Perl, Ruby, Bash and C. The goal of the challenge is simple: to create the classic "Hello World" program that runs under as many languages as possible in a single source file. The rules are that the interpreter or compiler for the language must be able to read the entire source file (so, for example you can't call "exit" in the middle to skip the rest of the file in an interpreted language), but you are allowed to use comments or a preprocessor if those features are available as standard in the language. The code can not require any non-standard libraries and it must run with the minimum command line arguments to get the interpreter or compiler read the code. The outputted string must be exactly "Hello, world!" (without the quotes) followed by a single newline character (0x0a). If anybody has any other ideas, please send them in to neil at busydoingnothing.co.uk. If you need inspiration for a different programming language, why not look at 99 Bottles of Beer or the list of programming languages on Wikipedia. Original programCreated by Neil Roberts, added 2005-06-06 download The original program on the blog entry. #ifdef NOT_C # skip C code for Perl, Ruby and Bash false && $skipme = <<END ; #endif #include <stdio.h> /* C */ int main (int argc, char **argv) { printf ("Hello, world!\n"); return 0; } #ifdef NOT_C END # For Perl and Ruby [ ] means an array/vector, which is true, but for # Bash it means to evaluate the expression which is false so the # command is skipped [ 1 == 2 ] && \ ( print "Hello, world!\n" ); # For Bash, the arguments to eval are concatenated and given to the # true command and so are ignored, but for Perl and Ruby the 'unless' # part is a separate clause which causes the whole eval command to be # skipped eval 'echo "Hello, world!" ; true' unless 1; #endif BefungedCreated by Robert Bragg, added 2005-08-22 download The original program squashed into an 80x25 grid with a Befunge program twisting through it. Note the nice use of the comma from the Bash and Ruby programs as the output instruction. #/* 0"!dl" v BEFUNGE CODE */ #ifdef NOT_C /* skip C code for Perl, Ruby and Bash */ false && $skipme = <<END ; # PERL RUBY AND BASH CODE # #endif /**/ #include <stdio.h> /* C CODE */ int /* C CODE */ main (int argc, char **argv) /* C CODE */ { /* C CODE */ printf ("Hello, world!\n"); /* C CODE */ return 0; /* C CODE */ } /* C CODE */ #ifdef NOT_C /* v"o""r"< */ /* > v >25*25**25*9++ v BEFUNGE CODE */ END # For Perl and Ruby [] means an array/vector, which is true, but for Bash it # # means to evaluate the expression which is false so the command is # # skipped. Befunge just uses the comma to output an ascii character. # [ 1 == 2 ] && ( print "Hello, world!\n" ); # PERL,RUBY,BASH AND BEFUNGE CODE# #For Bash, the arguments to eval are concatenated and given to the true # # command and so are ignored, but for Perl and Ruby the 'unless' part # # is a separate clause which causes the whole eval command to be skipped# eval 'echo "Hello, world!" ; true' unless 1; # BASH CODE # #endif /* ^ :#"Hello" ", "< BEFUNGE CODE */ #/* ^ _ 24*2+,@ BEFUNGE CODE */ #/*---- Ultimate Programming Challenge: C, Perl, Ruby, Bash and Befunge -----*/ |