in reply to Cheat at Scrabble
Wouldn't it be simpler to just do:
my %found; for ( 1 .. $length ) { my $P = Algorithm::Permute->new( \@input_chars, $_ ); while ( my @res = $P->next ) { my $word = join '', @res; $found{ $word } = calc_score( $word ) if exists $words{ $word +}; } }
And get rid of the @partials array altogether?
Also, the calc_score and calc_bonus functions could be combined:
sub calc_score { my @chars = split //, shift; my $val = 0; $val += $worth{ $_ } for @chars; $val += 50 if @chars == 7; my $bonus = 0; for ( @dl ) { $bonus += $worth{ $chars[ $_ - 1 ] } if $chars[ $_ - 1 ]; } for ( @tl ) { $bonus += 2 * $worth{ $chars[ $_ - 1 ] } if $chars[ $_ - 1 ]; } $bonus += $val if $dw; $bonus += 2 * $val if $tw; return $val + $bonus; }
|
|---|