develooper Front page | | Postings from August 2002

Re: TPR(0,5?) call for referees

Thread Previous | Thread Next
Juho Snellman
August 24, 2002 16:35
Re: TPR(0,5?) call for referees
Message ID:
On Sun, Aug 11, 2002 at 12:19:26AM +0300, Juho Snellman wrote:
> So, who's up for the glamorous job of golf referiing?

We've got plenty of Europeans now (thanks), but could really use 
someone living in a timezone more suitable for referiing during (about)
00:00-08:00 GMT.


Given a list of words on stdin (input lines matching /^[a-z]+$/i),
find the longest word that can be typed using only one key on a
cellular phone. The keyboard that I'm assuming produces the following
groups of characters from the same keys: ABC DEF GHI JKL MNO PQRS TUV
WXYZ. Or to put it another way, find the longest word that only
contains letters from one of the groups. If multiple equally long
words satisfy the condition, you may print any one of them.

For example, you should print either "feed\n" or "Abba\n" for this input:

It seems like there should be some exceedingly clever way to do this,
but I can barely make a one-liner out of it. Can anyone either improve
this, or figure out a better approach?

#!perl -p 
$a=$_;s/./(sort 7,9,(2..9)x3)[-97+ord lc$&]/ge>=length$\&/^(.)\1+$/and$\=$a}{

Juho Snellman
"C:stä on kehitetty Massachusettsin teknillisessä korkeakoulussa kieli
 nimeltä BCPL."  

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About