aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-09-26 01:01:48 +0100
committerGitHub <noreply@github.com>2022-09-26 01:01:48 +0100
commitc57599665c5bbc85a9e92acb40994f1f64a5065d (patch)
tree07c97270ccdd65bbf8dfd84eab33afdee772aadb
parent7225098ed8ac1917fb778f5ead144dfe10203eb2 (diff)
parentcda7ccb149e6e2b179327d3ad30e1425a18d4bb8 (diff)
downloadperlweeklychallenge-club-c57599665c5bbc85a9e92acb40994f1f64a5065d.tar.gz
perlweeklychallenge-club-c57599665c5bbc85a9e92acb40994f1f64a5065d.tar.bz2
perlweeklychallenge-club-c57599665c5bbc85a9e92acb40994f1f64a5065d.zip
Merge pull request #6793 from tcheukueppo/kueppo-pwc-183
Kueppo pwc 183
-rw-r--r--challenge-183/kueppo-wesley/Perl/ch-1.pl18
-rw-r--r--challenge-183/kueppo-wesley/Perl/ch-2.pl39
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-183/kueppo-wesley/Perl/ch-1.pl b/challenge-183/kueppo-wesley/Perl/ch-1.pl
new file mode 100644
index 0000000000..32a2cebd9d
--- /dev/null
+++ b/challenge-183/kueppo-wesley/Perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw(smartmatch);
+use feature qw(say);
+
+use Test::More;
+
+my @uniq;
+my @list = ( [ 9, 1 ], [ 3, 7 ], [ 2, 5 ], [ 2, 5 ] );
+
+# Man..... you gotta use `for(|each)'!!! :)
+map { my $aref = $_; push @uniq, $aref unless grep { @$aref ~~ @$_ } @uniq } @list;
+
+is_deeply( [@uniq], [ [ 9, 1 ], [ 3, 7, ], [ 2, 5 ] ] );
+
+done_testing( 1 );
diff --git a/challenge-183/kueppo-wesley/Perl/ch-2.pl b/challenge-183/kueppo-wesley/Perl/ch-2.pl
new file mode 100644
index 0000000000..bbc0428fc5
--- /dev/null
+++ b/challenge-183/kueppo-wesley/Perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use DateTime;
+use Test::More;
+
+my @result;
+my $dates = [
+ [ '2019-02-10', '2022-11-01' ],
+ [ '2020-09-15', '2022-03-29' ],
+ [ '2019-12-31', '2020-01-01' ],
+ [ '2019-12-01', '2019-12-31' ],
+ [ '2019-12-31', '2020-12-31' ],
+ [ '2019-12-31', '2021-12-31' ],
+ [ '2020-09-15', '2021-09-16' ],
+ [ '2019-09-15', '2021-09-16' ],
+];
+
+foreach my $date_pairs ( @$dates ) {
+ my @dp1 = split /-/, $date_pairs->[0];
+ my @dp2 = split /-/, $date_pairs->[1];
+
+ my $dt1 = DateTime->new( year => $dp1[0], month => $dp1[1], day => $dp1[2], time_zone => 'UTC' );
+ my $dt2 = DateTime->new( year => $dp2[0], month => $dp2[1], day => $dp2[2], time_zone => 'UTC' );
+
+ my $years = $dt2->subtract_datetime( $dt1 )->in_units( 'years' );
+ my $days = $dt2->subtract( years => $years )->jd - $dt1->jd;
+
+ push @result, [ $years, $days ];
+}
+
+is_deeply(
+ [@result],
+ [ [ 3, 264 ], [ 1, 195 ], [ 0, 1 ], [ 0, 30 ], [ 1, 0 ], [ 2, 0 ], [ 1, 1 ], [ 2, 1 ] ]
+);
+
+done_testing( 1 );