aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2025-06-16 11:51:07 -0600
committerLuis Mochan <mochan@fis.unam.mx>2025-06-16 11:51:07 -0600
commitc751d0d15b5d20e604c4d74f974a4dbd37078500 (patch)
treea8b45a688c91ecac2e2182e1568b498ef4536ef0
parent26cfae99bb0a2fdf9710bcc51e8abc8d7ed627f6 (diff)
downloadperlweeklychallenge-club-c751d0d15b5d20e604c4d74f974a4dbd37078500.tar.gz
perlweeklychallenge-club-c751d0d15b5d20e604c4d74f974a4dbd37078500.tar.bz2
perlweeklychallenge-club-c751d0d15b5d20e604c4d74f974a4dbd37078500.zip
Solve PWC326
-rw-r--r--challenge-326/wlmb/blog.txt1
-rwxr-xr-xchallenge-326/wlmb/perl/ch-1.pl27
-rwxr-xr-xchallenge-326/wlmb/perl/ch-2.pl15
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-326/wlmb/blog.txt b/challenge-326/wlmb/blog.txt
new file mode 100644
index 0000000000..9071479c8c
--- /dev/null
+++ b/challenge-326/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/06/16/PWC326/
diff --git a/challenge-326/wlmb/perl/ch-1.pl b/challenge-326/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..0ba8781150
--- /dev/null
+++ b/challenge-326/wlmb/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 326
+# Task 1: Day of the Year
+#
+# See https://wlmb.github.io/2025/06/16/PWC326/#task-1-day-of-the-year
+use v5.36;
+use List::Util qw(reductions);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 D1 D2...
+ to find the day number corresponding to the ISO dates D1, D2.
+ FIN
+my @days_in_month=(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+my @offsets=(0, reductions {$a+$b} @days_in_month);
+for(@ARGV){
+ say("Wrong format: $_"), next unless /^(\d{4})-(\d{2})-(\d{2})$/;
+ my ($year, $month, $day_of_month)=($1, $2, $3);
+ say("Wrong month: $_"), next unless 1 <= $month <= 12;
+ say("Wrong day: $_"), next
+ unless 1 <= $day_of_month
+ && ($day_of_month <= $days_in_month[$month] || $month == 2 && $day_of_month <= 29);
+ my $leap=$year%4==0;
+ $leap=0 if $year%100 == 0;
+ $leap=1 if $year%400 == 0;
+ my $day_of_year = $offsets[$month] + $day_of_month;
+ ++$day_of_year if $leap and $month >= 3;
+ say "$_ -> $day_of_year";
+}
diff --git a/challenge-326/wlmb/perl/ch-2.pl b/challenge-326/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..cded8c7327
--- /dev/null
+++ b/challenge-326/wlmb/perl/ch-2.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 326
+# Task 2: Decompressed List
+#
+# See https://wlmb.github.io/2025/06/16/PWC326/#task-2-decompressed-list
+use v5.36;
+die <<~"FIN" unless @ARGV and @ARGV%2==0;
+ Usage: $0 R1 N1 R2 N2...
+ to make a list with number Ni repeated Ri times.
+ FIN
+my @output=();
+for my($i,$j)(@ARGV){
+ push @output, ($j)x$i;
+}
+say "@ARGV -> @output"