What’s the most complex/powerful code you can write that’s valid in a maximum number of languages?
So, for example, the following code is valid in both PHP and JavaScript.
function foo($bar)
{
$var = 0;
for($i=0;$i<100;$i++)
{
$var += ($bar + 2)/(1+$i);
}
return $var;
}
Why is this a useful challenge? I think its a useful way to think about how similar languages can be, and how easily knowing one’s syntax can translate into learning another’s.
This is called a Polyglot, and it can get very complex. Here’s one in eight languages: http://ideology.com.au/polyglot/
Cobol, Pascal, Fortran, C, PostScript, bash, x86 machine language, and Perl: