diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-06 15:36:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 15:36:18 +0100 |
| commit | f04f7ceff2f3b2ebcea48cde0f59b4191050526f (patch) | |
| tree | 898d0c9f15c77a6e3663023750a282a6c37894aa | |
| parent | 61c15a3c13c605fed4b9686903578619db320c07 (diff) | |
| parent | 4c5627b4354339bf7f2a4b8fa956638b0e9df57e (diff) | |
| download | perlweeklychallenge-club-f04f7ceff2f3b2ebcea48cde0f59b4191050526f.tar.gz perlweeklychallenge-club-f04f7ceff2f3b2ebcea48cde0f59b4191050526f.tar.bz2 perlweeklychallenge-club-f04f7ceff2f3b2ebcea48cde0f59b4191050526f.zip | |
Merge pull request #11984 from wlmb/challenges
Solve PWC320
| -rw-r--r-- | challenge-320/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-320/wlmb/perl/ch-1.pl | 18 | ||||
| -rwxr-xr-x | challenge-320/wlmb/perl/ch-2.pl | 15 |
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-320/wlmb/blog.txt b/challenge-320/wlmb/blog.txt new file mode 100644 index 0000000000..d0ba8610e0 --- /dev/null +++ b/challenge-320/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/05/05/PWC320/ diff --git a/challenge-320/wlmb/perl/ch-1.pl b/challenge-320/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..91cf554632 --- /dev/null +++ b/challenge-320/wlmb/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Perl weekly challenge 320 +# Task 1: Maximum Count +# +# See https://wlmb.github.io/2025/05/05/PWC320/#task-1-maximum-count +use v5.36; +use List::Util qw(max); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 N2... + to find the maximum between the count of positive + and negative numbers among N1 N2... + FIN +my ($positive, $negative)=(0, 0); +for(@ARGV){ + ++$positive if $_>0; + ++$negative if $_<0; +} +say "@ARGV -> ",max($negative, $positive); diff --git a/challenge-320/wlmb/perl/ch-2.pl b/challenge-320/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..19eb234cf2 --- /dev/null +++ b/challenge-320/wlmb/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 320 +# Task 2: Sum Difference +# +# See https://wlmb.github.io/2025/05/05/PWC320/#task-2-sum-difference +use v5.36; +use List::Util qw(sum0 all); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 N2... + to compute the absolute value between the sum of the positive + intengers N1 N2... and the sum of their digits. + FIN +my @digits = map {split ""} @ARGV; +die "Only digits allowed" unless all {/[0-9]/} @digits; +say "@ARGV -> ", sum0(@ARGV)-sum0(@digits); |
