diff options
| -rw-r--r-- | challenge-326/mahnkong/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-326/mahnkong/perl/ch-2.pl | 21 |
2 files changed, 35 insertions, 0 deletions
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"); |
