From 3898bce7198df1752432e4fa099fd19637320b50 Mon Sep 17 00:00:00 2001 From: Andreas Mahnke Date: Mon, 16 Jun 2025 14:31:31 +0200 Subject: Challenge 326 --- challenge-326/mahnkong/perl/ch-1.pl | 14 ++++++++++++++ challenge-326/mahnkong/perl/ch-2.pl | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 challenge-326/mahnkong/perl/ch-1.pl create mode 100644 challenge-326/mahnkong/perl/ch-2.pl diff --git a/challenge-326/mahnkong/perl/ch-1.pl b/challenge-326/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..bf1233afce --- /dev/null +++ b/challenge-326/mahnkong/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; +use Time::Piece; + +sub run($date) { + my $time = Time::Piece->strptime($date,"%Y-%m-%d"); + return localtime($time)->[7] + 1; +} + +is(run('2025-02-02'), 33, "Example 1"); +is(run('2025-04-10'), 100, "Example 2"); +is(run('2025-09-07'), 250, "Example 3"); diff --git a/challenge-326/mahnkong/perl/ch-2.pl b/challenge-326/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..d0f4025d90 --- /dev/null +++ b/challenge-326/mahnkong/perl/ch-2.pl @@ -0,0 +1,21 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run(@ints) { + return undef if scalar(@ints) % 2 != 0; + + my @result; + while (scalar(@ints) > 0) { + my $m = shift @ints; + my $v = shift @ints; + push @result, $v for (1 .. $m); + } + + return [ @result ]; +} + +is_deeply(run(1, 3, 2, 4), [3, 4, 4], "Example 1"); +is_deeply(run(1, 1, 2, 2), [1, 2, 2], "Example 2"); +is_deeply(run(3, 1, 3, 2), [1, 1, 1, 2, 2, 2], "Example 3"); -- cgit