diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2025-05-05 20:36:00 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2025-05-05 20:36:00 -0600 |
| commit | 4c5627b4354339bf7f2a4b8fa956638b0e9df57e (patch) | |
| tree | a68830050beb14e4a3119c0640b6a011a6104c1d | |
| parent | 4865a9cce3c19c5a1def20017a083f17ef9a0809 (diff) | |
| download | perlweeklychallenge-club-4c5627b4354339bf7f2a4b8fa956638b0e9df57e.tar.gz perlweeklychallenge-club-4c5627b4354339bf7f2a4b8fa956638b0e9df57e.tar.bz2 perlweeklychallenge-club-4c5627b4354339bf7f2a4b8fa956638b0e9df57e.zip | |
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); |
