aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2025-06-09 10:32:09 -0600
committerLuis Mochan <mochan@fis.unam.mx>2025-06-09 10:32:09 -0600
commit14811a658033df929ca7c87e132dbd1bca1d2d77 (patch)
treeb7c686e0b0ee1c932b2d69da7ce6371368e4a284
parente28477d2418099cfbb1a227133c69ddef6eed741 (diff)
downloadperlweeklychallenge-club-14811a658033df929ca7c87e132dbd1bca1d2d77.tar.gz
perlweeklychallenge-club-14811a658033df929ca7c87e132dbd1bca1d2d77.tar.bz2
perlweeklychallenge-club-14811a658033df929ca7c87e132dbd1bca1d2d77.zip
Solve PWC325
-rw-r--r--challenge-325/wlmb/blog.txt1
-rwxr-xr-xchallenge-325/wlmb/perl/ch-1.pl18
-rwxr-xr-xchallenge-325/wlmb/perl/ch-2.pl19
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-325/wlmb/blog.txt b/challenge-325/wlmb/blog.txt
new file mode 100644
index 0000000000..4092365982
--- /dev/null
+++ b/challenge-325/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/06/09/PWC325/
diff --git a/challenge-325/wlmb/perl/ch-1.pl b/challenge-325/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..415ed0410c
--- /dev/null
+++ b/challenge-325/wlmb/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 325
+# Task 1: Consecutive One
+#
+# See https://wlmb.github.io/2025/06/09/PWC325/#task-1-consecutive-one
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 B1 B2...
+ to find the largest run of 1's among the bits B1 B2...
+ FIN
+my $current=0;
+my $max=0;
+for(@ARGV){
+ $current=0, next if $_==0;
+ ++$current, ($max<$current)&&($max=$current), next if $_==1;
+ die "Only 0's and 1's allowed: $_";
+}
+say "@ARGV -> $max";
diff --git a/challenge-325/wlmb/perl/ch-2.pl b/challenge-325/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..3908301004
--- /dev/null
+++ b/challenge-325/wlmb/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 325
+# Task 2: Final Price
+#
+# See https://wlmb.github.io/2025/06/09/PWC325/#task-2-final-price
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 P1 P2...
+ to apply discount to prices P1 P2...
+ A discount consists of subtracting from Pn the next possible Pm.
+ FIN
+my @results=@ARGV;
+for(0..@results-1){
+ for my $j($_+1..@results-1){
+ my $discounted=$results[$_]-$results[$j];
+ $results[$_]=$discounted,last if $discounted>=0;
+ }
+}
+say "@ARGV -> @results"