aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2019-06-27 16:16:40 -0400
committerDave Jacoby <jacoby.david@gmail.com>2019-06-27 16:16:40 -0400
commitb0898d6b9f102aa5f24df350ad9d87f21f37ba17 (patch)
tree9eb9be7876f92819943f2e36b55ec31aec11cdea
parentae17d3b757a6844dbf2842692b47392f057baa7c (diff)
parent7412f83547b291b434a7128660538f1675a80c82 (diff)
downloadperlweeklychallenge-club-b0898d6b9f102aa5f24df350ad9d87f21f37ba17.tar.gz
perlweeklychallenge-club-b0898d6b9f102aa5f24df350ad9d87f21f37ba17.tar.bz2
perlweeklychallenge-club-b0898d6b9f102aa5f24df350ad9d87f21f37ba17.zip
Merge branch 'master' of github.com:manwar/perlweeklychallenge-club
-rwxr-xr-xchallenge-012/feng-chang/perl5/ch-3.pl24
-rwxr-xr-xchallenge-013/feng-chang/perl5/ch-1.pl24
-rwxr-xr-xchallenge-013/feng-chang/perl5/ch-2.pl33
-rw-r--r--challenge-014/e-choroba/blog.txt1
-rwxr-xr-xchallenge-014/e-choroba/perl5/ch-2.pl2
-rwxr-xr-xchallenge-014/e-choroba/perl5/ch-2a.pl53
-rwxr-xr-xchallenge-014/feng-chang/perl5/ch-1.pl22
-rwxr-xr-xchallenge-014/feng-chang/perl5/ch-2.pl40
-rwxr-xr-xchallenge-014/feng-chang/perl6/ch-1.p618
-rwxr-xr-xchallenge-014/feng-chang/perl6/ch-2.p617
-rw-r--r--challenge-014/gustavo-chaves/perl5/README.pod42
-rwxr-xr-xchallenge-014/gustavo-chaves/perl5/ch-1-recursive.pl (renamed from challenge-014/gustavo-chaves/perl5/ch-1a.pl)28
-rwxr-xr-xchallenge-014/gustavo-chaves/perl5/ch-1.pl28
-rwxr-xr-xchallenge-014/gustavo-chaves/perl5/ch-2-all.pl40
-rwxr-xr-xchallenge-014/gustavo-chaves/perl5/ch-2.pl2
-rwxr-xr-xchallenge-014/gustavo-chaves/perl5/ch-extra.pl63
-rw-r--r--challenge-014/jaime/README37
-rw-r--r--challenge-014/jaime/perl5/ch-1.pl26
-rw-r--r--challenge-014/jaime/perl5/ch-2.pl20
-rw-r--r--challenge-014/neil-bowers/blog.txt1
-rw-r--r--challenge-014/shaun-pearce/README1
-rw-r--r--challenge-014/steven-wilson/blog.txt1
-rw-r--r--challenge-014/steven-wilson/perl5/README.md3
-rw-r--r--challenge-014/steven-wilson/perl5/ch-2.pl105
-rwxr-xr-xchallenge-014/walt-mankowski/perl5/ch-1.pl31
-rwxr-xr-xchallenge-014/walt-mankowski/perl5/ch-2.pl53
-rw-r--r--members.json1
-rw-r--r--script/refresh-stats.sh48
-rw-r--r--stats/pwc-challenge-001.json778
-rw-r--r--stats/pwc-challenge-002.json656
-rw-r--r--stats/pwc-challenge-003.json192
-rw-r--r--stats/pwc-challenge-004.json506
-rw-r--r--stats/pwc-challenge-005.json222
-rw-r--r--stats/pwc-challenge-006.json372
-rw-r--r--stats/pwc-challenge-007.json334
-rw-r--r--stats/pwc-challenge-008.json374
-rw-r--r--stats/pwc-challenge-009.json346
-rw-r--r--stats/pwc-challenge-010.json186
-rw-r--r--stats/pwc-challenge-011.json186
-rw-r--r--stats/pwc-challenge-012.json466
-rw-r--r--stats/pwc-challenge-013.json439
-rw-r--r--stats/pwc-current.json328
-rw-r--r--stats/pwc-language-breakdown-summary.json44
-rw-r--r--stats/pwc-language-breakdown.json150
-rw-r--r--stats/pwc-leaders.json938
-rw-r--r--stats/pwc-master-stats.json18
-rw-r--r--stats/pwc-summary-1-30.json102
-rw-r--r--stats/pwc-summary-31-60.json108
-rw-r--r--stats/pwc-summary-61-90.json58
-rw-r--r--stats/pwc-summary-91-120.json46
-rw-r--r--stats/pwc-summary.json258
51 files changed, 4300 insertions, 3571 deletions
diff --git a/challenge-012/feng-chang/perl5/ch-3.pl b/challenge-012/feng-chang/perl5/ch-3.pl
new file mode 100755
index 0000000000..ce69036c6b
--- /dev/null
+++ b/challenge-012/feng-chang/perl5/ch-3.pl
@@ -0,0 +1,24 @@
+#!/bin/env perl
+
+use Modern::Perl;
+use WWW::Mechanize;
+use XML::LibXML;
+
+exit unless @ARGV;
+
+my $m = WWW::Mechanize->new() or die "cannot initialize robot\n";
+
+my $base_url = 'http://www.stands4.com/services/v2/syno.php?uid=7082&tokenid=Bnm2q0xAKY2up6qQ';
+my $url = $base_url . "&word=$ARGV[0]&format=xml";
+
+$m->get($url);
+
+my $dom = XML::LibXML->load_xml(string => $m->content);
+foreach my $r ($dom->findnodes('//result')) {
+ say 'term: ', $r->findvalue('./term');
+ say ' definition: ', $r->findvalue('./definition');
+ say ' example: ', $r->findvalue('./example');
+ say ' partofspeech: ', $r->findvalue('./partofspeech');
+ say ' synonyms: ', $r->findvalue('./synonyms');
+ say ' antonyms: ', $r->findvalue('./antonyms');
+}
diff --git a/challenge-013/feng-chang/perl5/ch-1.pl b/challenge-013/feng-chang/perl5/ch-1.pl
new file mode 100755
index 0000000000..1f2c604bc2
--- /dev/null
+++ b/challenge-013/feng-chang/perl5/ch-1.pl
@@ -0,0 +1,24 @@
+#!/bin/env perl
+
+use Modern::Perl;
+use Date::Manip;
+
+sub is_leap_year {
+ my $year = shift;
+
+ return 1 if $year % 400 == 0;
+ return 0 if $year % 100 == 0;
+ return 1 if $year % 4 == 0;
+ return 0;
+}
+
+exit if @ARGV < 1;
+my $year = $ARGV[0];
+
+my @last_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+$last_days[1] = 29 if is_leap_year($year);
+
+for my $month (1..12) {
+ my $d = ParseDate("$year-$month-". $last_days[$month - 1]);
+ say UnixDate(DateCalc($d, sprintf('- %d days', (UnixDate($d, '%w') - 5) % 7)), '%Y/%m/%d');
+}
diff --git a/challenge-013/feng-chang/perl5/ch-2.pl b/challenge-013/feng-chang/perl5/ch-2.pl
new file mode 100755
index 0000000000..27b72c67ce
--- /dev/null
+++ b/challenge-013/feng-chang/perl5/ch-2.pl
@@ -0,0 +1,33 @@
+#!/bin/env perl
+
+use Modern::Perl;
+
+my @F = (1);
+my @M = (0);
+
+sub F {
+ my $n = int(shift);
+ exit if $n < 0;
+
+ return $F[$n] if defined $F[$n];
+
+ $F[$n] = $n - M(F($n - 1));
+}
+
+sub M {
+ my $n = int(shift);
+ exit if $n < 0;
+
+ return $M[$n] if defined $M[$n];
+
+ $M[$n] = $n - F(M($n - 1));
+}
+
+exit unless defined $ARGV[0];
+my $n = $ARGV[0];
+
+print(F($_), ' ') for 0 .. $n - 1;
+say '';
+
+print(M($_), ' ') for 0 .. $n - 1;
+say '';
diff --git a/challenge-014/e-choroba/blog.txt b/challenge-014/e-choroba/blog.txt
new file mode 100644
index 0000000000..92de29c1a2
--- /dev/null
+++ b/challenge-014/e-choroba/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/e_choroba/2019/06/perl-weekly-challenge-014-van-eck-and-the-us-states.html
diff --git a/challenge-014/e-choroba/perl5/ch-2.pl b/challenge-014/e-choroba/perl5/ch-2.pl
index ca5a4dc3e8..514b92cdfe 100755
--- a/challenge-014/e-choroba/perl5/ch-2.pl
+++ b/challenge-014/e-choroba/perl5/ch-2.pl
@@ -18,8 +18,6 @@ while (my $word = <$in>) {
my $uc_word = uc $word;
my @pairs = $uc_word =~ /\G(..)/g;
- next if length $uc_word != 2 * @pairs;
-
next if grep ! exists $states{$_}, @pairs;
next if length($word) < length $longest[0];
diff --git a/challenge-014/e-choroba/perl5/ch-2a.pl b/challenge-014/e-choroba/perl5/ch-2a.pl
new file mode 100755
index 0000000000..65df78f69e
--- /dev/null
+++ b/challenge-014/e-choroba/perl5/ch-2a.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+use Cpanel::JSON::XS;
+
+my $json = <DATA>;
+
+my $data = Cpanel::JSON::XS->new->decode($json);
+my %by_initials;
+undef $by_initials{$data->{$_}{initials}}{$_} for keys %$data;
+
+my @longest = ([""]);
+while (my $word = <>) {
+ chomp $word;
+ $word = lc $word;
+ if (my @path = path($word, [])) {
+ if (length $word > length $longest[0][0]) {
+ @longest = ([$word, \@path]);
+ } elsif (length $word == length $longest[0][0]) {
+ push @longest, [$word, \@path];
+ }
+ }
+}
+
+say "$_->[0]: ", map { map "[@$_] ", @$_ } @{ $_->[1] } for @longest;
+
+
+sub path {
+ my ($rest, $path) = @_;
+
+ return [$path] if "" eq $rest;
+
+ my @solutions;
+ for my $length (1, 2) {
+ next if $length > length $rest;
+
+ my $prefix = substr $rest, 0, $length;
+ next unless exists $by_initials{$prefix};
+
+ for my $state (keys %{ $by_initials{$prefix} }) {
+ next if @$path
+ && ((grep $_ eq $state, @$path)
+ || ! grep $state eq $_,
+ @{ $data->{ $path->[-1] }{adjacent} });
+ push @solutions, path(substr($rest, $length), [ @$path, $state ]);
+ }
+ }
+ return @solutions
+}
+__DATA__
+{"AL":{"name":"Alabama","initials":"a","adjacent":["FL","GA","TN","MS"]},"AK":{"name":"Alaska","initials":"a","adjacent":[]},"AZ":{"name":"Arizona","initials":"a","adjacent":["NM","UT","NV","CA"]},"AR":{"name":"Arkansas","initials":"a","adjacent":["LA","MS","TN","MO","OK","TX"]},"CA":{"name":"California","initials":"c","adjacent":["AZ","NV","OR"]},"CO":{"name":"Colorado","initials":"c","adjacent":["NM","OK","KS","NE","WY","UT"]},"CT":{"name":"Connecticut","initials":"c","adjacent":["RI","MA","NY"]},"DE":{"name":"Delaware","initials":"d","adjacent":["NJ","PA","MD"]},"FL":{"name":"Florida","initials":"f","adjacent":["GA","AL"]},"GA":{"name":"Georgia","initials":"g","adjacent":["SC","NC","TN","AL","FL"]},"HI":{"name":"Hawaii","initials":"h","adjacent":[]},"ID":{"name":"Idaho","initials":"i","adjacent":["WA","OR","NV","UT","WY","MT"]},"IL":{"name":"Illinois","initials":"i","adjacent":["WI","IA","MO","KY","IN"]},"IN":{"name":"Indiana","initials":"i","adjacent":["IL","KY","OH","MI"]},"IA":{"name":"Iowa","initials":"i","adjacent":["MN","SD","NE","MO","IL","WI"]},"KS":{"name":"Kansas","initials":"k","adjacent":["OK","MO","NE","CO"]},"KY":{"name":"Kentucky","initials":"k","adjacent":["TN","VA","WV","OH","IN","IL","MO"]},"LA":{"name":"Louisiana","initials":"l","adjacent":["MS","AR","TX"]},"ME":{"name":"Maine","initials":"m","adjacent":["NH"]},"MD":{"name":"Maryland","initials":"m","adjacent":["DE","PA","WV","VA"]},"MA":{"name":"Massachusetts","initials":"m","adjacent":["NH","VT","NY","CT","RI"]},"MI":{"name":"Michigan","initials":"m","adjacent":["WI","IN","OH"]},"MN":{"name":"Minnesota","initials":"m","adjacent":["ND","SD","IA","WI"]},"MS":{"name":"Mississippi","initials":"m","adjacent":["AL","TN","AR","LA"]},"MO":{"name":"Missouri","initials":"m","adjacent":["AR","TN","KY","IL","IA","NE","KS","OK"]},"MT":{"name":"Montana","initials":"m","adjacent":["ID","WY","SD","ND"]},"NE":{"name":"Nebraska","initials":"n","adjacent":["KS","MO","IA","SD","WY","CO"]},"NV":{"name":"Nevada","initials":"n","adjacent":["AZ","UT","ID","OR","CA"]},"NH":{"name":"NewHampshire","initials":"nh","adjacent":["VT","MA","ME"]},"NJ":{"name":"NewJersey","initials":"nj","adjacent":["NY","PA","DE"]},"NM":{"name":"NewMexico","initials":"nm","adjacent":["TX","OK","CO","AZ"]},"NY":{"name":"NewYork","initials":"ny","adjacent":["PA","NJ","CT","MA","VT"]},"NC":{"name":"NorthCarolina","initials":"nc","adjacent":["VA","TN","GA","SC"]},"ND":{"name":"NorthDakota","initials":"nd","adjacent":["MT","SD","MN"]},"OH":{"name":"Ohio","initials":"o","adjacent":["MI","IN","KY","WV","PA"]},"OK":{"name":"Oklahoma","initials":"o","adjacent":["TX","AR","MO","KS","CO","NM"]},"OR":{"name":"Oregon","initials":"o","adjacent":["CA","NV","ID","WA"]},"PA":{"name":"Pennsylvania","initials":"p","adjacent":["OH","WV","MD","DE","NJ","NY"]},"RI":{"name":"RhodeIsland","initials":"ri","adjacent":["MA","CT"]},"SC":{"name":"SouthCarolina","initials":"sc","adjacent":["NC","GA"]},"SD":{"name":"SouthDakota","initials":"sd","adjacent":["NE","IA","MN","ND","MT","WY"]},"TN":{"name":"Tennessee","initials":"t","adjacent":["AL","GA","NC","VA","KY","MO","AR","MS"]},"TX":{"name":"Texas","initials":"t","adjacent":["LA","AR","OK","NM"]},"UT":{"name":"Utah","initials":"u","adjacent":["AZ","CO","WY","ID","NV"]},"VT":{"name":"Vermont","initials":"v","adjacent":["NY","MA","NH"]},"VA":{"name":"Virginia","initials":"v","adjacent":["MD","WV","KY","TN","NC"]},"WA":{"name":"Washington","initials":"w","adjacent":["OR","ID"]},"WV":{"name":"WestVirginia","initials":"wv","adjacent":["VA","MD","PA","OH","KY"]},"WI":{"name":"Wisconsin","initials":"w","adjacent":["MN","IA","IL","MI"]},"WY":{"name":"Wyoming","initials":"w","adjacent":["CO","NE","SD","MT","ID","UT"]}}
diff --git a/challenge-014/feng-chang/perl5/ch-1.pl b/challenge-014/feng-chang/perl5/ch-1.pl
new file mode 100755
index 0000000000..91815b7ad5
--- /dev/null
+++ b/challenge-014/feng-chang/perl5/ch-1.pl
@@ -0,0 +1,22 @@
+#!/bin/env perl
+
+use Modern::Perl;
+
+my @eck = (0, 0);
+
+exit unless defined $ARGV[0];
+my $n = int($ARGV[0]);
+exit if $n < 2;
+
+for my $i (2 .. $n) {
+ $eck[$i] = 0;
+
+ for (my $j = $i - 2; $j >= 0; --$j) {
+ if ($eck[$j] == $eck[$i - 1]) {
+ $eck[$i] = $i - $j - 1;
+ last;
+ }
+ }
+}
+
+say join(' ', @eck);
diff --git a/challenge-014/feng-chang/perl5/ch-2.pl b/challenge-014/feng-chang/perl5/ch-2.pl
new file mode 100755
index 0000000000..74159cb8e0
--- /dev/null
+++ b/challenge-014/feng-chang/perl5/ch-2.pl
@@ -0,0 +1,40 @@
+#!/bin/env perl
+
+use Modern::Perl;
+
+my @aUSPS = qw(
+ al ak az ar ca co ct de fl ga
+ hi id il in ia ks ky la me md
+ ma mi mn ms mo mt ne nv nh nj
+ nm ny nc nd oh ok or pa ri sc
+ sd tn tx ut vt va wa wv wi wy
+);
+
+my %hUSPS;
+map { $hUSPS{ $_ } = 1 } @aUSPS;
+
+my @words;
+my $max_len = 0;
+
+open my $fh, '<', '/usr/share/dict/words' or die "cannot read /usr/share/dict/words\n";
+
+myloop:
+while (my $w = <$fh>) {
+ chomp $w;
+ $w = lc($w);
+
+ for my $p ($w =~ m/..?/g) {
+ next myloop unless $hUSPS{ $p };
+ }
+
+ push @words, $w;
+ my $len = length $w;
+ $max_len = $len if $len > $max_len;
+}
+close $fh;
+
+say "max word length is $max_len";
+
+for my $w (@words) {
+ say $w if length($w) == $max_len;
+}
diff --git a/challenge-014/feng-chang/perl6/ch-1.p6 b/challenge-014/feng-chang/perl6/ch-1.p6
new file mode 100755
index 0000000000..7fe81fe8ea
--- /dev/null
+++ b/challenge-014/feng-chang/perl6/ch-1.p6
@@ -0,0 +1,18 @@
+#!/bin/env perl6
+
+sub MAIN(UInt $n) {
+ my @eck = 0, 0;
+
+ for 2..$n -> Int $i {
+ @eck[$i] = 0;
+
+ for $i - 2 ... 0 -> Int $j {
+ if @eck[$j] == @eck[$i - 1] {
+ @eck[$i] = $i - $j - 1;
+ last;
+ }
+ }
+ }
+
+ say @eck;
+}
diff --git a/challenge-014/feng-chang/perl6/ch-2.p6 b/challenge-014/feng-chang/perl6/ch-2.p6
new file mode 100755
index 0000000000..5c11db745a
--- /dev/null
+++ b/challenge-014/feng-chang/perl6/ch-2.p6
@@ -0,0 +1,17 @@
+#!/bin/env perl6
+
+my @usps = <
+ al ak az ar ca co ct de fl ga
+ hi id il in ia ks ky la me md
+ ma mi mn ms mo mt ne nv nh nj
+ nm ny nc nd oh ok or pa ri sc
+ sd tn tx ut vt va wa wv wi wy
+>;
+
+my @words = '/usr/share/dict/words'.IO.lines».lc.grep({ all($_.comb(2)) ∈ @usps }).unique;
+
+my Int $max-length = @words».chars.max;
+say "max word length is $max-length";
+
+my @longest-words = @words.grep: { $_.chars == $max-length };
+say @longest-words;
diff --git a/challenge-014/gustavo-chaves/perl5/README.pod b/challenge-014/gustavo-chaves/perl5/README.pod
index 3eb671d407..b01ac3c1f9 100644
--- a/challenge-014/gustavo-chaves/perl5/README.pod
+++ b/challenge-014/gustavo-chaves/perl5/README.pod
@@ -19,7 +19,7 @@ The recursive solution is a little easier to grasp, I think, because it's a more
direct expression of the sequence's definition. But even using memoization it's
33 times slower than the iterative version.
- $ ./ch-1a.pl 10
+ $ ./ch-1-recursive.pl 10
0
0
1
@@ -31,7 +31,7 @@ direct expression of the sequence's definition. But even using memoization it's
1
6
- $ ./ch-1b.pl 10
+ $ ./ch-1-iterative.pl 10
0
0
1
@@ -60,8 +60,44 @@ the US Postal Codes.
But I was dumbfounded when I ran it and saw the result:
- $ ./ch-2.pl
+ $ ./ch-2-one.pl
Campinas
Campinas is the name of the city where I live, in Brazil. But I don't have a
clue what is it doing in an English dictionary! :-)
+
+After having sent my solutions it downed on me that there could be more than one
+"largest" word in the dictionary. So, I implemented a second version which
+prints all of them:
+
+ $ ./ch-2-all.pl
+ Campinas
+ Concorde
+ Ganymede
+ Mandarin
+ Victoria
+ calamine
+ complain
+ mainland
+ malarial
+ mandarin
+ mascaras
+ memorial
+ moorland
+
+=head1 #extra US Traversal
+
+Neil Bowers blogged about this challenge saying that the second problem wasn't
+exactly the one he proposed. He explained what he actually had in mind in a
+L<blog post|http://neilb.org/2019/06/24/additional-challenge-14.html>.
+
+Basically, he wants to know what is the largest English word that can be made
+using only the initials if US states, beginning in any of them and following
+only adjacent states. He offered a JSON data structure in a GitHub Gist
+containing the ajdacency and initials of the states.
+
+Using the Linux dictionary in F</usr/share/dict/words> my script tells me that
+the word is "fatal":
+
+ $ ./ch-extra.pl
+ fatal (Florida => Alabama => Tennessee => Arkansas => Louisiana)
diff --git a/challenge-014/gustavo-chaves/perl5/ch-1a.pl b/challenge-014/gustavo-chaves/perl5/ch-1-recursive.pl
index 3b24e8a570..98002f0cad 100755
--- a/challenge-014/gustavo-chaves/perl5/ch-1a.pl
+++ b/challenge-014/gustavo-chaves/perl5/ch-1-recursive.pl
@@ -5,26 +5,32 @@
# (https://en.wikipedia.org/wiki/Van_Eck%27s_sequence). This challenge was
# proposed by team member Andrezgz.
-# This is an iterative implementation, which is more than 30x faster than the
-# recursive one.
+# This is a recursive implementation.
use 5.026;
use strict;
use warnings;
+use Memoize;
my $sequence_size = shift or die "Usage: $0 SIZE\n";
-my @sequence = (0);
+memoize('van_ecks');
+sub van_ecks {
+ my ($n) = @_;
-VALUE:
-for my $i (0 .. $sequence_size-2) {
- for (my $j=$i-1; $j >= 0; --$j) {
- if ($sequence[$j] == $sequence[$i]) {
- push @sequence, $i-$j;
- next VALUE;
+ return 0 if $n <= 1;
+
+ my $previous_value = van_ecks($n-1);
+
+ for (my $i=$n-2; $i >= 0; --$i) {
+ if (van_ecks($i) == $previous_value) {
+ return ($n-1) - $i;
}
}
- push @sequence, 0;
+
+ return 0;
}
-say foreach @sequence;
+for my $i (0 .. $sequence_size-1) {
+ say van_ecks($i);
+}
diff --git a/challenge-014/gustavo-chaves/perl5/ch-1.pl b/challenge-014/gustavo-chaves/perl5/ch-1.pl
index 98002f0cad..3b24e8a570 100755
--- a/challenge-014/gustavo-chaves/perl5/ch-1.pl
+++ b/challenge-014/gustavo-chaves/perl5/ch-1.pl
@@ -5,32 +5,26 @@
# (https://en.wikipedia.org/wiki/Van_Eck%27s_sequence). This challenge was
# proposed by team member Andrezgz.
-# This is a recursive implementation.
+# This is an iterative implementation, which is more than 30x faster than the
+# recursive one.
use 5.026;
use strict;
use warnings;
-use Memoize;
my $sequence_size = shift or die "Usage: $0 SIZE\n";
-memoize('van_ecks');
-sub van_ecks {
- my ($n) = @_;
+my @sequence = (0);
- return 0 if $n <= 1;
-
- my $previous_value = van_ecks($n-1);
-
- for (my $i=$n-2; $i >= 0; --$i) {
- if (van_ecks($i) == $previous_value) {
- return ($n-1) - $i;
+VALUE:
+for my $i (0 .. $sequence_size-2) {
+ for (my $j=$i-1; $j >= 0; --$j) {
+ if ($sequence[$j] == $sequence[$i]) {
+ push @sequence, $i-$j;
+ next VALUE;
}
}
-
- return 0;
+ push @sequence, 0;
}
-for my $i (0 .. $sequence_size-1) {
- say van_ecks($i);
-}
+say foreach @sequence;
diff --git a/challenge-014/gustavo-chaves/perl5/ch-2-all.pl b/challenge-014/gustavo-chaves/perl5/ch-2-all.pl
new file mode 100755
index 0000000000..726576f4a3
--- /dev/null
+++ b/challenge-014/gustavo-chaves/perl5/ch-2-all.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+# 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?
+# Here is the list of U.S. states abbreviations as per wikipedia page
+# (https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations). This
+# challenge was proposed by team member Neil Bowers.
+
+# This version prints all the largest words.
+
+use 5.026;
+use strict;
+use autodie;
+use warnings;
+use Locale::US;
+use List::Util qw(all);
+
+my @postal_codes = Locale::US->new()->all_state_codes();
+my %postal_codes = map {lc($_) => undef} @postal_codes;
+
+my $largest_length_so_far = 0;
+my @largest_words_so_far;
+
+open my $dict, '<', '/usr/share/dict/words';
+while (<$dict>) {
+ chomp;
+ my $word = $_;
+ next unless length($word) >= $largest_length_so_far;
+ next unless (length($word) % 2) == 0;
+ next unless all {exists $postal_codes{$_}} (lc($word) =~ m/../g);
+ if (length($word) == $largest_length_so_far) {
+ push @largest_words_so_far, $word;
+ } else {
+ $largest_length_so_far = length($word);
+ @largest_words_so_far = ($word);
+ }
+}
+close $dict;
+
+say foreach @largest_words_so_far;
diff --git a/challenge-014/gustavo-chaves/perl5/ch-2.pl b/challenge-014/gustavo-chaves/perl5/ch-2.pl
index 66a3bc60bd..1ef5e6c00e 100755
--- a/challenge-014/gustavo-chaves/perl5/ch-2.pl
+++ b/challenge-014/gustavo-chaves/perl5/ch-2.pl
@@ -6,6 +6,8 @@
# (https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations). This
# challenge was proposed by team member Neil Bowers.
+# This version prints the first largest word.
+
use 5.026;
use strict;
use autodie;
diff --git a/challenge-014/gustavo-chaves/perl5/ch-extra.pl b/challenge-014/gustavo-chaves/perl5/ch-extra.pl
new file mode 100755
index 0000000000..c5f21c3e25
--- /dev/null
+++ b/challenge-014/gustavo-chaves/perl5/ch-extra.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+
+# http://neilb.org/2019/06/24/additional-challenge-14.html
+
+use 5.026;
+use strict;
+use autodie;
+use warnings;
+use LWP::Simple;
+use JSON;
+
+my $usa_state_data_url = 'https://gist.githubusercontent.com/neilb/ee60cd179d5eb17d1cb616cdeeda760f/raw/3d31a508a5277ddb4df3a73fb14715102b452302/usa-state-data.json';
+
+my $usa_state_data_json = get($usa_state_data_url)
+ or die "Could not get $usa_state_data_url";
+
+my $usa_state_data = decode_json($usa_state_data_json);
+
+my @all_states = sort keys %$usa_state_data;
+
+# Mark all states are non-visited yet.
+$_->{visited} = 0 foreach values %$usa_state_data;
+
+sub is_traversable_via {
+ my ($word, $adjacents) = @_;
+
+ foreach my $state (@{$usa_state_data}{@$adjacents}) {
+ next if $state->{visited};
+ my $initials = $state->{initials};
+ next if $initials ne substr($word, 0, length($initials));
+ return ($state) if length($initials) eq length($word);
+ local $state->{visited} = 1;
+ if (my @path = is_traversable_via(substr($word, length($initials)), $state->{adjacent})) {
+ return ($state, @path);
+ }
+ }
+
+ return;
+}
+
+my $largest_length_so_far = 0;
+my @largest_words_so_far;
+
+open my $dict, '<', '/usr/share/dict/words';
+while (<$dict>) {
+ chomp;
+ my $word = $_;
+ next unless length($word) >= $largest_length_so_far;
+ if (my @path = is_traversable_via(lc $word, \@all_states)) {
+ if (length($word) == $largest_length_so_far) {
+ push @largest_words_so_far, [$word, \@path];
+ } else {
+ $largest_length_so_far = length($word);
+ @largest_words_so_far = ([$word, \@path]);
+ }
+ }
+}
+close $dict;
+
+foreach (@largest_words_so_far) {
+ my ($word, $path) = @$_;
+ say $word, ' (', join(' => ', map {$_->{name}} @$path), ')';
+}
diff --git a/challenge-014/jaime/README b/challenge-014/jaime/README
index 6b98f9b732..9acbfee5ea 100644
--- a/challenge-014/jaime/README
+++ b/