diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-13 13:21:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-13 13:21:49 +0100 |
| commit | d94e36e448d8e4ddd8e04da51470e6e4467d6862 (patch) | |
| tree | bd54068a8f9e0752334ea8bc556dc53d1bd98c04 | |
| parent | 8ac9237f3ee78a2c281f85e001987694a8f535e7 (diff) | |
| parent | 99babfc50bce161b593f208100951aced1d140b8 (diff) | |
| download | perlweeklychallenge-club-d94e36e448d8e4ddd8e04da51470e6e4467d6862.tar.gz perlweeklychallenge-club-d94e36e448d8e4ddd8e04da51470e6e4467d6862.tar.bz2 perlweeklychallenge-club-d94e36e448d8e4ddd8e04da51470e6e4467d6862.zip | |
Merge pull request #12018 from wlmb/challenges
Solve PWC321
| -rw-r--r-- | challenge-321/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-321/wlmb/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-321/wlmb/perl/ch-2.pl | 21 |
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-321/wlmb/blog.txt b/challenge-321/wlmb/blog.txt new file mode 100644 index 0000000000..1e32450d96 --- /dev/null +++ b/challenge-321/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/05/12/PWC321/ diff --git a/challenge-321/wlmb/perl/ch-1.pl b/challenge-321/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..ec97838dd8 --- /dev/null +++ b/challenge-321/wlmb/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +# Perl weekly challenge 321 +# Task 1: Distinct Average +# +# See https://wlmb.github.io/2025/05/12/PWC321/#task-1-distinct-average +use v5.36; +use List::Util qw(uniq); +my $N=@ARGV; +die <<~"FIN" unless $N && $N%2==0; + Usage: $0 N1 N2...N2n + to remove the smallest and largest value of the list, average them and + count the distinct values produced. + FIN +my @sorted = sort {$a <=> $b} @ARGV; +my $N2 = $N/2-1; # +say "@ARGV -> ", scalar uniq map {$sorted[$_]+$sorted[-1-$_]} 0..$N2; diff --git a/challenge-321/wlmb/perl/ch-2.pl b/challenge-321/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..a7ecb9ca5f --- /dev/null +++ b/challenge-321/wlmb/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +# Perl weekly challenge 321 +# Task 2: Backspace Compare +# +# See https://wlmb.github.io/2025/05/12/PWC321/#task-2-backspace-compare +use v5.36; +die <<~"FIN" unless @ARGV && @ARGV%2==0; + Usage: $0 A1 B1 A2 B2... + to find if strings An Bn are equal after all \#'s are + interpreted as backspace and applied to delete the preceding + character. + FIN +for my($x, $y)(@ARGV){ + my ($x_edited, $y_edited) = ($x, $y); # make a copy + ($x_edited, $y_edited) = map { + 1 while s/(^|[^\#])\#//g; # apply backspaces. Deal with # at beginning + $_; # return edited string + } ($x_edited, $y_edited); + my $result = $x_edited eq $y_edited? "True" : "False"; + say "$x $y -> $result"; +} |
