Sha256: d663213cecedd737d0cbae0afc88240d6b933eb8167252420789e277b2b42f8d

Contents?: true

Size: 607 Bytes

Versions: 323

Compression:

Stored size: 607 Bytes

Contents

package Example;

use strict;
use warnings;
use List::Util 'first';

sub new {
    my ($class, $word) = @_;
    return bless { word => lc $word } => $class;
}
sub score {
    my ($self, %extension) = @_;
    my $score = 0;

    my %values = qw(
        aeioulnrst 1 dg 2 bcmp 3 fhvwy 4
        k 5 jx 8 qz 10
        ZERO 0
    );

    foreach my $c (split '' => $self->{word}) {
        $score += $values{ first { /$c/ } keys %values or 'ZERO' }
    }

    $score *= (2 ** $extension{double}) if $extension{double};
    $score *= (3 ** $extension{triple}) if $extension{triple};

    return $score ;
}

1;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/scrabble-score/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/scrabble-score/Example.pm