aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-18 05:50:13 +0100
committerGitHub <noreply@github.com>2021-10-18 05:50:13 +0100
commit448dd90b46bb45d02b1207689e7ecf5bcf5ceca9 (patch)
treeb2738cd8e125dd0eb14054b8229ddfaae89fa462
parent63b1cbe63c92c19b35afd9ec4846709565c7da30 (diff)
parentafe7c6d4db5ba5212bd34af78caa336c137c6bbb (diff)
downloadperlweeklychallenge-club-448dd90b46bb45d02b1207689e7ecf5bcf5ceca9.tar.gz
perlweeklychallenge-club-448dd90b46bb45d02b1207689e7ecf5bcf5ceca9.tar.bz2
perlweeklychallenge-club-448dd90b46bb45d02b1207689e7ecf5bcf5ceca9.zip
Merge pull request #5049 from jaldhar/challenge-132
Challenge 132 by Jaldhar H. Vyas.
-rw-r--r--challenge-132/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-132/jaldhar-h-vyas/perl/ch-1.pl12
-rwxr-xr-xchallenge-132/jaldhar-h-vyas/perl/ch-2.pl54
-rwxr-xr-xchallenge-132/jaldhar-h-vyas/raku/ch-1.raku11
-rwxr-xr-xchallenge-132/jaldhar-h-vyas/raku/ch-2.raku55
5 files changed, 133 insertions, 0 deletions
diff --git a/challenge-132/jaldhar-h-vyas/blog.txt b/challenge-132/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..979cca8313
--- /dev/null
+++ b/challenge-132/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2021/10/perl_weekly_challenge_week_132.html
diff --git a/challenge-132/jaldhar-h-vyas/perl/ch-1.pl b/challenge-132/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..9bcdc4cf74
--- /dev/null
+++ b/challenge-132/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+use DateTime;
+
+my $birthday = DateTime->new(year => 1971, month => 3, day => 22);
+my $today = DateTime->today;
+my $diff = $today->jd - $birthday->jd;
+
+my $past = $birthday->subtract(days => $diff);
+my $future = $today->add(days => $diff);
+say $past->ymd(q{/}), q{, }, $future->ymd(q{/});
diff --git a/challenge-132/jaldhar-h-vyas/perl/ch-2.pl b/challenge-132/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..a6922e1b57
--- /dev/null
+++ b/challenge-132/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+
+my @output;
+
+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 $col0length = 0;
+my $col1length = 0;
+my $col2length = 0;
+
+for my $r (@player_ages) {
+ for my $s (@player_names) {
+ if ($r->[1] eq $s->[0]) {
+
+ push @output, [ $r->[0], "\"$r->[1]\"", "\"$s->[1]\"" ];
+
+ if (length $r->[0] > $col0length) {
+ $col0length = length $r->[0];
+ }
+
+ if (length $r->[1] > $col1length) {
+ $col1length = length $r->[1];
+ }
+
+ if (length $s->[1] > $col2length) {
+ $col2length = length $s->[1];
+ }
+ }
+ }
+}
+
+for my $row (sort { $a->[1] cmp $b->[1] } @output) {
+ printf
+ "%-${\($col0length + 1)}s %-${\($col1length + 3)}s %-${\($col2length + 2)}s\n",
+ $row->[0] . q{,}, $row->[1] . q{,}, $row->[2];
+}
diff --git a/challenge-132/jaldhar-h-vyas/raku/ch-1.raku b/challenge-132/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..cee625f749
--- /dev/null
+++ b/challenge-132/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,11 @@
+#!/usr/bin/raku
+
+sub MAIN() {
+ my $birthday = Date.new('1971-03-22');
+ my $today = Date.today;
+ my $diff = $today - $birthday;
+
+ my $past = $birthday - $diff;
+ my $future = $today + $diff;
+ say $past.yyyy-mm-dd(q{/}), q{, }, $future.yyyy-mm-dd(q{/});
+} \ No newline at end of file
diff --git a/challenge-132/jaldhar-h-vyas/raku/ch-2.raku b/challenge-132/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..7e72202d09
--- /dev/null
+++ b/challenge-132/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,55 @@
+#!/usr/bin/raku
+
+sub MAIN() {
+ my @output;
+
+ 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 $col0length = 0;
+ my $col1length = 0;
+ my $col2length = 0;
+
+ for @player_ages -> @r {
+ for @player_names -> @s {
+ if @r[1] eq @s[0] {
+
+ @output.push([ @r[0], "\"@r[1]\"", "\"@s[1]\"" ]);
+
+ if @r[0].chars > $col0length {
+ $col0length = @r[0].chars;
+ }
+
+ if @r[1].chars > $col1length {
+ $col1length = @r[1].chars;
+ }
+
+ if @s[1].chars > $col2length {
+ $col2length = @s[1].chars;
+ }
+ }
+ }
+ }
+
+ for @output.sort({ @^a[1] cmp @^b[1] }) -> @row {
+ printf
+ "%-{$col0length + 1}s %-{$col1length + 3}s %-{$col2length + 2}s\n",
+ @row[0] ~ q{,}, @row[1] ~ q{,}, @row[2];
+ }
+
+} \ No newline at end of file