http://qs321.pair.com?node_id=139244

...because they are too difficult to type with one hand.

icicle, oxidize, panels, soaped, coaxial, dispels,
gospels, spatial, clamps, dispel, elapse, gospel,
pajama, palely, panama, lapels, and social.

YuckFoo

#!/usr/bin/perl use strict; my ($DICT, $MIN) = qw(/usr/dict/words 6); my (%rows, %cols); my ($word, $score); addhash(0, \%rows, \%cols, 'qwertyuiop'); addhash(1, \%rows, \%cols, 'asdfghjkl'); addhash(2, \%rows, \%cols, 'zxcvbnm'); if (!open (IN, $DICT)) { print STDERR "\nError opening file: $DICT\n\n"; exit; } while (chomp ($word = <IN>)) { if (length($word) >= $MIN && $word !~ m{[A-Z]}) { $score = score(\%rows, \%cols, $word); printf (STDOUT "%4.2f $word\n", $score); } } #----------------------------------------------------------- sub score { my ($rows, $cols, $str) = @_; my ($tot, $ch); my ($r, $c, $lr, $lc); for $ch (split('', $str)) { if ($lr eq '') { ($lr, $lc) = ($rows->{$ch}, $cols->{$ch}); } else { ($r, $c) = ($rows->{$ch}, $cols->{$ch}); $tot += abs($lr - $r) + abs($lc - $c); ($lr, $lc) = ($r, $c); } } return ($tot / (length($str) - 1)); } #----------------------------------------------------------- sub addhash { my ($row, $rows, $cols, $str) = @_; my ($i, $ch); for $ch (split('', $str)) { ($rows->{$ch}, $cols->{$ch}) = ($row, $i++); } }

Replies are listed 'Best First'.
Re: Words that suck...
by ChemBoy (Priest) on Jan 16, 2002 at 22:53 UTC

    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

      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)

(sacked) Re: Words that suck...
by sacked (Hermit) on Jan 16, 2002 at 22:17 UTC
Re: Words that suck...
by clintp (Curate) on Jan 16, 2002 at 22:44 UTC
    Which begs the question: why are you typing them with one hand? I can't remember any of those words occuring during a pornographic discussion... well, except maybe "clamps". :)
      Just to dispel the gospel, she had to oxidize her pajama lapel after having socially soaped my icicle.... :P