aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-10 09:22:38 +0100
committerGitHub <noreply@github.com>2025-06-10 09:22:38 +0100
commit334f076ff50cea88ea1e1807dd801b4f90ae9dae (patch)
tree9c29e3c199d808f3bdb7eb5834d650f06aa49212
parente2acf0d6a834bb5e14b6540e0f7ffe60f64c2c67 (diff)
parent14811a658033df929ca7c87e132dbd1bca1d2d77 (diff)
downloadperlweeklychallenge-club-334f076ff50cea88ea1e1807dd801b4f90ae9dae.tar.gz
perlweeklychallenge-club-334f076ff50cea88ea1e1807dd801b4f90ae9dae.tar.bz2
perlweeklychallenge-club-334f076ff50cea88ea1e1807dd801b4f90ae9dae.zip
Merge pull request #12157 from wlmb/challenges
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"