Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Words that suck...

by ChemBoy (Priest)
on Jan 16, 2002 at 22:53 UTC ( [id://139280]=note: print w/replies, xml ) Need Help??


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

unless length < $MIN || /[A-Z]/;
though I know some would argue against that move.

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...



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Replies are listed 'Best First'.
Re: Re: Words that suck...
by YuckFoo (Abbot) on Jan 17, 2002 at 04:10 UTC
    Thanks for you thoughts ChemBoy. You can see I lean to high byte constructions. It always seems to me that conditions should come before statements (ducks).

    This was a ten minute hack to show a coworker how lame the passwords he makes up are, I have to use them.

    Not sure I agree about which string is easier, 'asdfghjkl' is a single keystroke and a swipe. But indeed some words have a momentum component that is not scored.

    Also the keyboard wasn't quite properly layed out, an offset is probably needed. If 'w' is column 1, shouldn't 's' be column 1.2 and 'x' be column 1.9?

    Also I shouldn't just add the row distance to the col distance something more like sqrt(dr*dr+dc*dc) maybe.

    Obviously scoring is flawed because 'social' scores harder than 'socialize'. Length should play more of a factor.

    Caps should be implemented with high penalty for 'Y'. Perhaps a typo probability for those pinky letters that'll trigger backspaces?

    You're right, so many variations I punted.

    clintp, if you've never used 'icicle' or 'coaxial' for one handed adult conversations, you're not doing it right.

    YuckFoo

    -who wishes his name was Fred (score=1) instead of Edward (score=2.2)

    -but is glad his name is not Pamela (7.6) or Claudia (6.83)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://139280]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found