diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2025-06-16 07:06:49 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2025-06-16 07:06:49 +0000 |
| commit | b77dfc4db5ba805b19a110eb3bbb623e7698ea96 (patch) | |
| tree | ce27977e6717566c2bfedfa600e12e4c71949f12 | |
| parent | 26cfae99bb0a2fdf9710bcc51e8abc8d7ed627f6 (diff) | |
| download | perlweeklychallenge-club-b77dfc4db5ba805b19a110eb3bbb623e7698ea96.tar.gz perlweeklychallenge-club-b77dfc4db5ba805b19a110eb3bbb623e7698ea96.tar.bz2 perlweeklychallenge-club-b77dfc4db5ba805b19a110eb3bbb623e7698ea96.zip | |
w326 - Task 1 &2
| -rwxr-xr-x | challenge-326/perlboy1967/perl/ch1.pl | 32 | ||||
| -rwxr-xr-x | challenge-326/perlboy1967/perl/ch2.pl | 33 |
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-326/perlboy1967/perl/ch1.pl b/challenge-326/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..f194426bb6 --- /dev/null +++ b/challenge-326/perlboy1967/perl/ch1.pl @@ -0,0 +1,32 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 326 +L<https://theweeklychallenge.org/blog/perl-weekly-challenge-326#TASK1> + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Day of the Year +Submitted by: Mohammad Sajid Anwar + +You are given a date in the format YYYY-MM-DD. + +Write a script to find day number of the year that the given date represent. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use Time::Piece; + +sub dayOfTheYear ($date) { + Time::Piece->strptime($date, '%Y-%m-%d')->yday + 1 +} + +is(dayOfTheYear('2025-02-02'),33,'Example 1'); +is(dayOfTheYear('2025-04-10'),100,'Example 2'); +is(dayOfTheYear('2025-09-07'),250,'Example 3'); + +done_testing; diff --git a/challenge-326/perlboy1967/perl/ch2.pl b/challenge-326/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..1d542bf4bd --- /dev/null +++ b/challenge-326/perlboy1967/perl/ch2.pl @@ -0,0 +1,33 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 326 +L<https://theweeklychallenge.org/blog/perl-weekly-challenge-326#TASK2> + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Decompressed List +Submitted by: Mohammad Sajid Anwar + +You are given an array of positive integers having even elements. + +Write a script to to return the decompress list. To decompress, pick +adjacent pair (i, j) and replace it with j, i times. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(pairmap); + +sub decompress (@c) { + pairmap { ($b) x $a } @c; +} + +is([decompress(1,3,2,4)],[3,4,4],'Example 1'); +is([decompress(1,1,2,2)],[1,2,2],'Example 2'); +is([decompress(3,1,3,2)],[1,1,1,2,2,2],'Example 3'); + +done_testing; |
