]> git.donarmstrong.com Git - bin.git/commitdiff
add scrabble score
authorDon Armstrong <don@donarmstrong.com>
Fri, 14 Feb 2014 00:13:35 +0000 (16:13 -0800)
committerDon Armstrong <don@donarmstrong.com>
Fri, 14 Feb 2014 00:13:35 +0000 (16:13 -0800)
scrabble_score [new file with mode: 0755]

diff --git a/scrabble_score b/scrabble_score
new file mode 100755 (executable)
index 0000000..92ef5ef
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+my %tile_values = ('a' => 1, 'b' => 3, 'c' => 3, 'd' => 2,
+                  'e' => 1, 'f' => 4, 'g' => 2, 'h' => 4,
+                  'i' => 1, 'j' => 8, 'k' => 5, 'l' => 1,
+                  'm' => 3, 'n' => 1, 'o' => 1, 'p' => 3,
+                  'q' => 10, 'r' => 1, 's' => 1, 't' => 1,
+                  'u' => 1, 'v' => 4, 'w' => 4, 'x' => 8,
+                  'y' => 4, 'z' => 10, "\*" => 0);
+
+use List::Util qw(sum);
+
+while (<>) {
+    chomp;
+    my $score = sum(map {$tile_values{lc($_)}} split //);
+    print $score . ' '.$_."\n";
+}