aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2025-08-25 20:42:24 -0600
committerLuis Mochan <mochan@fis.unam.mx>2025-08-25 20:42:24 -0600
commitded21cf8720a5062af141cf1fa2063e093e27db3 (patch)
treed2eb62786641af188db9b57c7ac1b407a5c8dda6
parentcfe111699674dcbdae6a9172888ec4a0cf5ca4c1 (diff)
downloadperlweeklychallenge-club-ded21cf8720a5062af141cf1fa2063e093e27db3.tar.gz
perlweeklychallenge-club-ded21cf8720a5062af141cf1fa2063e093e27db3.tar.bz2
perlweeklychallenge-club-ded21cf8720a5062af141cf1fa2063e093e27db3.zip
Solve PWC336
-rw-r--r--challenge-336/wlmb/blog.txt1
-rwxr-xr-xchallenge-336/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-336/wlmb/perl/ch-2.pl33
3 files changed, 51 insertions, 0 deletions
diff --git a/challenge-336/wlmb/blog.txt b/challenge-336/wlmb/blog.txt
new file mode 100644
index 0000000000..cc3040fc79
--- /dev/null
+++ b/challenge-336/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/08/25/PWC336/
diff --git a/challenge-336/wlmb/perl/ch-1.pl b/challenge-336/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..e74fe3af9d
--- /dev/null
+++ b/challenge-336/wlmb/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 336
+# Task 1: Equal Group
+#
+# See https://wlmb.github.io/2025/08/25/PWC336/#task-1-equal-group
+use v5.36;
+use Math::Prime::Util qw(gcd);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S1 S2...
+ to find if the space separated numbers Nj within the string Ni
+ may be grouped into equal sized groups of two or more elements.
+ FIN
+for(@ARGV){
+ my %count;
+ $count{$_}++ for split " ";
+ say "$_ -> ", gcd(values %count) > 1?"True":"False";
+}
diff --git a/challenge-336/wlmb/perl/ch-2.pl b/challenge-336/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..608583896e
--- /dev/null
+++ b/challenge-336/wlmb/perl/ch-2.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 336
+# Task 2: Final Score
+#
+# See https://wlmb.github.io/2025/08/25/PWC336/#task-2-final-score
+use v5.36;
+use List::Util qw(sum0);
+use feature qw(try);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S1 S2...
+ to perform the space separated operations Oj in strings Si
+ and print the resulting score.
+ The operations are
+ a number, push it
+ +, push the sum of the last two numbers
+ C, clear the last number
+ D, push twice the last number
+ FIN
+for(@ARGV){
+ my @scores;
+ try {
+ for(split " "){
+ push(@scores, ($scores[-1]//0)+($scores[-2]//0)), next if /^\+$/;
+ push(@scores, ($scores[-1]//0)*2), next if /^D|d$/;
+ @scores&&pop(@scores), next if /^C|c$/;
+ push(@scores, $_), next if /^(\+|-)?\d+$/;
+ die "Expected +, D, C or number: $_";
+ }
+ say "$_ -> ", sum0 @scores;
+ } catch($e) {
+ say $e;
+ }
+}