diff options
| -rw-r--r-- | challenge-132/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-132/wlmb/perl/ch-1.pl | 21 | ||||
| -rwxr-xr-x | challenge-132/wlmb/perl/ch-2.pl | 23 |
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-132/wlmb/blog.txt b/challenge-132/wlmb/blog.txt new file mode 100644 index 0000000000..4b0b01dfb8 --- /dev/null +++ b/challenge-132/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2021/09/28/PWC132/ diff --git a/challenge-132/wlmb/perl/ch-1.pl b/challenge-132/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..c6f11f61bd --- /dev/null +++ b/challenge-132/wlmb/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +# Perl weekly challenge 131 +# Task 1: Consecutive arrays +# +# See https://wlmb.github.io/2021/09/28/PWC132/#task-1-mirror-dates + +use v5.12; +use warnings; +use DateTime; +use DateTime::Format::DateParse; +my ($date_s, $current_s)=@ARGV; +my $date=DateTime::Format::DateParse->parse_datetime($date_s)->truncate(to=>'day'); +die "Wrong date: ", $date_s//"" unless defined $date; +my $current=DateTime::Format::DateParse->parse_datetime($current_s)->truncate(to=>'day'); +die "Wrong date: ", $current_s//"" if not defined $current and defined $current_s; +$current//=DateTime->today->truncate(to=>'day'); +my $difference=$current-$date; +my $previous=$date-$difference; +my $next=$current+$difference; +say sprintf "Input: %s, Current: %s\nOutput: %s, %s", + map {$_->ymd} ($date, $current, $previous, $next); diff --git a/challenge-132/wlmb/perl/ch-2.pl b/challenge-132/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..2e56377831 --- /dev/null +++ b/challenge-132/wlmb/perl/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# Perl weekly challenge 132 +# Task 2: Hash join +# +# See https://wlmb.github.io/2021/09/28/PWC132/#task-2-hash-join +use v5.24; # To use the funny syntax ->@* +use warnings; +use YAML::XS; + +my ($index_build, $index_probe)= map {shift} @ARGV; # indices for join comparison +$/=''; #slurp +my $input=Load(my $data=<>); # Parse input +my @build=$input->[0]->@*; # Array of build tuples +my @probe=$input->[1]->@*; # Array of probe tuples +my %build; # Build hash. Each entry is array of tuples. +# Build complete 'build' hash. I assume it fits in memory. +push $build{$_->[$index_build]}->@*, $_ foreach(@build); +foreach my $tuple(@probe){ # Iterate over probe tuples + my $key=splice @$tuple,$index_probe,1; # remove and assign key + # Array of all matching build tuples. Empty if none + my @matching=defined $build{$key}?$build{$key}->@*:(); # first parts of + say join ", ", $_->@*, @$tuple foreach @matching; # Join one build one probe tuple +} |
