aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-219/wlmb/blog.txt2
-rwxr-xr-xchallenge-219/wlmb/perl/ch-1.pl13
-rwxr-xr-xchallenge-219/wlmb/perl/ch-2.pl25
3 files changed, 40 insertions, 0 deletions
diff --git a/challenge-219/wlmb/blog.txt b/challenge-219/wlmb/blog.txt
new file mode 100644
index 0000000000..4b59e70921
--- /dev/null
+++ b/challenge-219/wlmb/blog.txt
@@ -0,0 +1,2 @@
+https://wlmb.github.io/2023/05/29/PWC219/
+
diff --git a/challenge-219/wlmb/perl/ch-1.pl b/challenge-219/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..4f4d3e4743
--- /dev/null
+++ b/challenge-219/wlmb/perl/ch-1.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 219
+# Task 1: Sorted Squares
+#
+# See https://wlmb.github.io/2023/05/29/PWC219/#task-1-sorted-squares
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 -- N1 [N2...]
+ to square and sort the numbers N1 N2...
+ The -- is to allow negative numbers as arguments without
+ confusing them with options.
+ FIN
+say "@ARGV ->", join " ", sort {$a<=>$b} map {$_**2} @ARGV;
diff --git a/challenge-219/wlmb/perl/ch-2.pl b/challenge-219/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..8e8602097a
--- /dev/null
+++ b/challenge-219/wlmb/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 219
+# Task 2: Travel Expenditure
+#
+# See https://wlmb.github.io/2023/05/29/PWC219/#task-2-travel-expenditure
+use v5.36;
+use List::Util qw(min);
+die <<~"FIN" unless @ARGV > 3;
+ Usage: $0 C1 C7 C30 D1 [D2...]
+ to calculate the travel expenditure for days D1, D2...
+ given the costs C1 C7 and C30 for one, seven and thirty day passes
+ FIN
+my @kinds=(1,7,30); # kinds of passes
+my @days=@ARGV;
+my @costs=splice @days, 0, 3;
+my $expenditure=cost(0, @days);
+say "Costs: @costs, Days: @days, Expenditure: $expenditure";
+
+sub cost($current, @days){
+ shift @days while @days and $current >= $days[0];
+ return 0 unless @days;
+ my $now=shift(@days);
+ my $cost=min map {$costs[$_]+cost($now+$kinds[$_]-1, @days)} 0..2;
+ return $cost;
+}