Flipped the if statement to make it the Perl way
much tighter implementation
C implementation
minor improvements; printing results at the end
Using a ternary operator; use buffering for printing out
Python implementation