diff options
| -rw-r--r-- | challenge-325/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-325/wlmb/perl/ch-1.pl | 18 | ||||
| -rwxr-xr-x | challenge-325/wlmb/perl/ch-2.pl | 19 |
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" |
