aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-26 10:50:52 +0100
committerGitHub <noreply@github.com>2025-08-26 10:50:52 +0100
commit30a8541cafa5ef40f0ae631163012af58e2ae28f (patch)
tree72afed49fa3229e5b9aba55acae47fc126886c14
parent1b7b044290aae025ab151f177927432f39ef9a02 (diff)
parentded21cf8720a5062af141cf1fa2063e093e27db3 (diff)
downloadperlweeklychallenge-club-30a8541cafa5ef40f0ae631163012af58e2ae28f.tar.gz
perlweeklychallenge-club-30a8541cafa5ef40f0ae631163012af58e2ae28f.tar.bz2
perlweeklychallenge-club-30a8541cafa5ef40f0ae631163012af58e2ae28f.zip
Merge pull request #12579 from wlmb/challenges
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;
+ }
+}