04 September 2013

FizzBuzz in Perl One-Liner

Last week something caused me to remember the Obfuscated Perl Contest that used to take place back in the 1990s in The Perl Journal (all issues available here.

Here is FizzBuzz in a Perl one-liner. Why? Because I can.

perl -e 'for (my $i=1; $i<100; ++$i) {($i%3==0 and $i%5==0) ? print "FizzBuzz\n" : (($i%3==0) ? print "Fizz\n" : (($i%5==0) ? print "Buzz\n" : print "$i\n"))}'

No comments:

Post a Comment