aboutsummaryrefslogtreecommitdiff
path: root/challenge-132
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-10-04 02:16:36 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-10-04 02:16:36 +0100
commitecc34a2666ccf3966a887cb83d31248dca45ecb0 (patch)
tree30d71676adabad50e8ef6306eeb99ac8ac64165c /challenge-132
parent31e6be25dc0305abdc5c24e6336d4b50fd1a8d51 (diff)
downloadperlweeklychallenge-club-ecc34a2666ccf3966a887cb83d31248dca45ecb0.tar.gz
perlweeklychallenge-club-ecc34a2666ccf3966a887cb83d31248dca45ecb0.tar.bz2
perlweeklychallenge-club-ecc34a2666ccf3966a887cb83d31248dca45ecb0.zip
- Added Perl solutions to week 132.
Diffstat (limited to 'challenge-132')
-rw-r--r--challenge-132/mohammad-anwar/perl/ch-1.pl32
-rw-r--r--challenge-132/mohammad-anwar/perl/ch-2.pl50
2 files changed, 82 insertions, 0 deletions
diff --git a/challenge-132/mohammad-anwar/perl/ch-1.pl b/challenge-132/mohammad-anwar/perl/ch-1.pl
new file mode 100644
index 0000000000..f6fea8290c
--- /dev/null
+++ b/challenge-132/mohammad-anwar/perl/ch-1.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+=head1
+
+Week 132:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-132
+
+Task #1: Mirror Dates
+
+ You are given a date (yyyy/mm/dd).
+
+ Assuming, the given date is your date of birth. Write a script to find the mirror dates of the given date.
+
+=cut
+
+use strict;
+use warnings;
+
+use Date::Calc qw(Today Date_to_Days Add_Delta_Days);
+
+my $DATE = $ARGV[0];
+
+my ($c_year, $c_month, $c_day) = Today();
+my ($g_year, $g_month, $g_day) = split /\//, $DATE, 3;
+
+my $days = Date_to_Days($c_year, $c_month, $c_day)
+ -
+ Date_to_Days($g_year, $g_month, $g_day);
+
+print sprintf("%04d/%02d/%02d\n", Add_Delta_Days($g_year, $g_month, $g_day, -$days));
+print sprintf("%04d/%02d/%02d\n", Add_Delta_Days($c_year, $c_month, $c_day, $days));
diff --git a/challenge-132/mohammad-anwar/perl/ch-2.pl b/challenge-132/mohammad-anwar/perl/ch-2.pl
new file mode 100644
index 0000000000..08fc1ca0f2
--- /dev/null
+++ b/challenge-132/mohammad-anwar/perl/ch-2.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+=head1
+
+Week 132:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-132
+
+Task #2: Hash Join
+
+ Write a script to implement Hash Join algorithm as suggested by wikipedia.
+
+=cut
+
+use strict;
+use warnings;
+
+my @player_ages = (
+ [20, "Alex" ],
+ [28, "Joe" ],
+ [38, "Mike" ],
+ [18, "Alex" ],
+ [25, "David" ],
+ [18, "Simon" ],
+);
+
+my @player_names = (
+ ["Alex", "Stewart"],
+ ["Joe", "Root" ],
+ ["Mike", "Gatting"],
+ ["Joe", "Blog" ],
+ ["Alex", "Jones" ],
+ ["Simon","Duane" ],
+);
+
+my $names = {
+ map {
+ join(" ", @$_) => { f => $_->[0], l => $_->[1] }
+ } @player_names
+};
+
+foreach my $player (@player_ages) {
+ my $first_name = $player->[1];
+ my $age = $player->[0];
+ foreach my $n (keys %$names) {
+ if ($names->{$n}->{f} eq $first_name) {
+ print "$age, $first_name, $names->{$n}->{l}\n";
+ }
+ }
+}