Interesting that the shortest (and among the most readable) is the 15-line version written in old-school AWK:
http://pacman.blog.br/wiki/index.php?title=Um_Corretor_Ortog...
A surprise is that the Perl implementation weighs in at 63 lines. I would have expected much less. I expect a much shorter version is possible, relying on idiomatic constructs at the expense of readability.