From 4c5627b4354339bf7f2a4b8fa956638b0e9df57e Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 5 May 2025 20:36:00 -0600 Subject: Solve PWC320 --- challenge-320/wlmb/blog.txt | 1 + challenge-320/wlmb/perl/ch-1.pl | 18 ++++++++++++++++++ challenge-320/wlmb/perl/ch-2.pl | 15 +++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 challenge-320/wlmb/blog.txt create mode 100755 challenge-320/wlmb/perl/ch-1.pl create mode 100755 challenge-320/wlmb/perl/ch-2.pl 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); -- cgit