aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-16 21:56:35 +0100
committerGitHub <noreply@github.com>2025-06-16 21:56:35 +0100
commit67327fddd3aa428ae3a253f926f3ebd91e1d92d7 (patch)
tree688df198e5f89ebb09d127c62e06a2037fd6fe7b
parentac137a65b84af2e049e6e6c059ad01381404d387 (diff)
parent08d6a24525ec575cb688f0bc083de5f83e0f8497 (diff)
downloadperlweeklychallenge-club-67327fddd3aa428ae3a253f926f3ebd91e1d92d7.tar.gz
perlweeklychallenge-club-67327fddd3aa428ae3a253f926f3ebd91e1d92d7.tar.bz2
perlweeklychallenge-club-67327fddd3aa428ae3a253f926f3ebd91e1d92d7.zip
Merge pull request #12191 from choroba/ech326
Solve 326: Day of the Year & Decompressed List by E. Choroba
-rwxr-xr-xchallenge-326/e-choroba/perl/ch-1.pl19
-rwxr-xr-xchallenge-326/e-choroba/perl/ch-2.pl19
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-326/e-choroba/perl/ch-1.pl b/challenge-326/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..26b78b42aa
--- /dev/null
+++ b/challenge-326/e-choroba/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use Time::Piece;
+
+sub day_of_the_year($date) {
+ my $tp = 'Time::Piece'->strptime($date, '%Y-%m-%d');
+ return 1 + $tp->yday
+}
+
+use Test::More tests => 3 + 1;
+
+is day_of_the_year('2025-02-02'), 33, 'Example 1';
+is day_of_the_year('2025-04-10'), 100, 'Example 2';
+is day_of_the_year('2025-09-07'), 250, 'Example 3';
+
+is day_of_the_year('2024-09-07'), 251, 'Leap year';
diff --git a/challenge-326/e-choroba/perl/ch-2.pl b/challenge-326/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..def571797d
--- /dev/null
+++ b/challenge-326/e-choroba/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub decompressed_list(@ints) {
+ my @r;
+ while (my ($times, $what) = splice @ints, 0, 2) {
+ push @r, ($what) x $times;
+ }
+ return @r
+}
+
+use Test2::V0;
+plan(3);
+
+is [decompressed_list(1, 3, 2, 4)], [3, 4, 4], 'Example 1';
+is [decompressed_list(1, 1, 2, 2)], [1, 2, 2], 'Example 2';
+is [decompressed_list(3, 1, 3, 2)], [1, 1, 1, 2, 2, 2], 'Example 3';