Disconnected Mutterings of a Random Geek

Fri, 10 Nov 2006

Palindromes, revisted

Strib pointed out that my palindrome checking could be better. First off, using all the usernames, and not just the ones with email addresses attached, found two more palindromic usernames. bb which is for big brother, and pgp, which is the user whose $HOME is pgp binaries. Doesn't everyone use gpg yet?

He also thought that my code could be faster. His first effort was 3 times slower, and my attempt to make it non-recursive only gave 5 ms more speed. Then he unleashed perl, and wrote:

time perl -ne 'chomp;print "$_\n" if $_ eq reverse $_' < /tmp/users

Which is an order of magnitude faster, mainly startup time. I then wrote one in C, which used all sorts of tricks to me a bit faster, and takes about 6ms, which is an order of magnitude faster than perl, considering that vega takes 4ms to tell you that a command doesn't exist, it aint getting much faster.

posted at: 10:54 | path: /computing | permanent link to this entry

Made with PyBlosxom