commit 47debcf9033cd0ef22b472bfde47e3f6511fa33c parent 5757adfc44a3aa9ac13c208464bd9a2ceb22172b Author: Samir Parikh <noreply@samirparikh.com> Date: Mon, 14 Feb 2022 20:42:00 +0000 get all tests to pass for scrabble score Diffstat:
M | scrabble-score/ScrabbleScore.pm | | | 12 | +++++++++++- |
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/scrabble-score/ScrabbleScore.pm b/scrabble-score/ScrabbleScore.pm @@ -6,7 +6,17 @@ our @EXPORT_OK = qw<scrabble_score>; sub scrabble_score { my ($word) = @_; - return undef; + my $score = 0; + my %letter_value; + $letter_value{ $_ } = 1 foreach (qw( A E I O U L N R S T )); + $letter_value{ $_ } = 2 foreach (qw( D G )); + $letter_value{ $_ } = 3 foreach (qw( B C M P)); + $letter_value{ $_ } = 4 foreach (qw( F H V W Y)); + $letter_value{ K } = 5; + $letter_value{ $_ } = 8 foreach (qw( J X )); + $letter_value{ $_ } = 10 foreach (qw( Q Z )); + $score += $letter_value{ uc $_ } foreach ( split //, $word ); + return $score; } 1;