From b77dfc4db5ba805b19a110eb3bbb623e7698ea96 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 16 Jun 2025 07:06:49 +0000 Subject: w326 - Task 1 &2 --- challenge-326/perlboy1967/perl/ch1.pl | 32 ++++++++++++++++++++++++++++++++ challenge-326/perlboy1967/perl/ch2.pl | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 challenge-326/perlboy1967/perl/ch1.pl create mode 100755 challenge-326/perlboy1967/perl/ch2.pl 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 + +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 + +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; -- cgit