in reply to Words that suck...
Neat! I disagree, though, with your for- and while-loop construction. I have a weakness for low-byte constructions, of course, but I really think it's easier to read that main loop as
while (<IN>) { chomp; printf "%4.2f $_\n", score (\%rows, \%cols,$_) if length >=$MIN && not /[A-Z]/; }
In fact, given my druthers, I'd invert the logic to
though I know some would argue against that move.unless length < $MIN || /[A-Z]/;
And while I'm engaged in pointless nitpicking (<grin>), wouldn't it be more appropriate to change the scoring algorithm so that it wouldn't penalize for column shifts that could be managed without moving your hand? As it stands, "asdfdsa" and "asdfghjkl" both score 1.0,though it's obviously much easier to type the former...
Of course, there are more or less infinite variations on how one could score that (which may be why you didn't try), but as a first attempt, how about this?
sub score { my ($rows, $cols, $str) = @_; my ($tot, $ch); my ($r, $c, $lr, $lc); my ($leastc,$mostc); ($ch) = $str =~ /(.)/; ($lr, $lc,$leastc,$mostc) = ($rows->{$ch}, ($cols->{$ch}) x 3); for $ch (split('', $str)) { ($r, $c) = ($rows->{$ch}, $cols->{$ch}); $tot += abs($lr - $r) + abs($lc - $c); $leastc = $c if $c < $leastc; $mostc = $c if $c > $mostc; ($lr, $lc) = ($r, $c); } return ($tot / (length($str) - 1) + ($mostc-$leastc) / 3); }
I don't think that's the best adjustment to apply, though--it's just the easiest. Maybe a floor function there (that is, int ( ($mostc-$leastc) / 3) ))? Hmmm...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Words that suck...
by YuckFoo (Abbot) on Jan 17, 2002 at 04:10 UTC |