aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2019-06-30 01:31:16 -0400
committerAdam Russell <ac.russell@live.com>2019-06-30 01:31:16 -0400
commitf23ff956b43615db5f5774f785396113229c76b1 (patch)
treeb958bb6616751e53008dc1f92bd0f4b3c676a150
parent6f77e37cd4c56a8be6a4e9cfa223039312b6ac5f (diff)
downloadperlweeklychallenge-club-f23ff956b43615db5f5774f785396113229c76b1.tar.gz
perlweeklychallenge-club-f23ff956b43615db5f5774f785396113229c76b1.tar.bz2
perlweeklychallenge-club-f23ff956b43615db5f5774f785396113229c76b1.zip
solutions for challenge 014
-rw-r--r--challenge-014/adam-russell/blog.txt1
-rw-r--r--challenge-014/adam-russell/perl5/ch-1.pl15
-rw-r--r--challenge-014/adam-russell/perl5/ch-2.pl82
3 files changed, 98 insertions, 0 deletions
diff --git a/challenge-014/adam-russell/blog.txt b/challenge-014/adam-russell/blog.txt
new file mode 100644
index 0000000000..54f5ab38b5
--- /dev/null
+++ b/challenge-014/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/4974.html
diff --git a/challenge-014/adam-russell/perl5/ch-1.pl b/challenge-014/adam-russell/perl5/ch-1.pl
new file mode 100644
index 0000000000..5779cbd9e0
--- /dev/null
+++ b/challenge-014/adam-russell/perl5/ch-1.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+##
+# Write a script to generate Van Eck’s sequence starts with 0.
+##
+my $i = 1;
+my @sequence = (0, 0);
+print join(" ", @sequence) . " ";
+{
+ my $last_index = (sort { $b <=> $a} grep { $sequence[$_] == $sequence[$i] } 0..(@sequence - 2))[0];
+ $i++;
+ $sequence[$i] = defined($last_index) ? ($i - $last_index - 1) : 0;
+ print $sequence[$i] . " ";
+ redo;
+}
diff --git a/challenge-014/adam-russell/perl5/ch-2.pl b/challenge-014/adam-russell/perl5/ch-2.pl
new file mode 100644
index 0000000000..917dc75f02
--- /dev/null
+++ b/challenge-014/adam-russell/perl5/ch-2.pl
@@ -0,0 +1,82 @@
+use strict;
+use warnings;
+##
+# Using only the official postal (2-letter) abbreviations for
+# the 50 U.S. states, write a script to find the longest English
+# word you can spell.
+##
+my %word_product;
+my %letter_factor = (
+ AL => 2,
+ AK => 2,
+ AZ => 2,
+ AR => 2,
+ CA => 2,
+ CO => 2,
+ CT => 2,
+ DE => 2,
+ FL => 2,
+ GA => 2,
+ HI => 2,
+ ID => 2,
+ IL => 2,
+ IN => 2,
+ IA => 2,
+ KS => 2,
+ KY => 2,
+ LA => 2,
+ ME => 2,
+ MD => 2,
+ MA => 2,
+ MI => 2,
+ MN => 2,
+ MS => 2,
+ MO => 2,
+ MT => 2,
+ NE => 2,
+ NV => 2,
+ NH => 2,
+ NJ => 2,
+ NM => 2,
+ NY => 2,
+ NC => 2,
+ ND => 2,
+ OH => 2,
+ OK => 2,
+ OR => 2,
+ PA => 2,
+ RI => 2,
+ SC => 2,
+ SD => 2,
+ TN => 2,
+ TX => 2,
+ UT => 2,
+ VT => 2,
+ VA => 2,
+ WA => 2,
+ WV => 2,
+ WI => 2,
+ WY => 2
+);
+map { $letter_factor{ lc($_) } = $letter_factor{ $_ }; delete($letter_factor{ $_ }) } keys %letter_factor;
+
+##
+# Main
+##
+while(<>){
+ chomp($_);
+ my $word = lc($_);
+ $word =~ tr/-//d;
+ my @letters = split(//, $word);
+ if(@letters % 2 == 0){
+ my @two_letter_chunks;
+ for(my $i = 0; $i < @letters; $i+=2){
+ push @two_letter_chunks, $letters[$i] . $letters[$i + 1];
+ }
+ my $product = 1;
+ map {$product *= $_} map{defined($letter_factor{$_}) ? $letter_factor{$_} : 0} @two_letter_chunks;
+ $word_product{$word} = $product if($product > 0);
+ }
+}
+my @sorted = sort {$word_product{$b} <=> $word_product{$a}} keys %word_product;
+print $sorted[0] . "\n";