aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2025-08-26 18:39:05 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2025-08-26 18:39:05 -0400
commita60e110825aedc3295dfd1e033e2f2c6441d03c2 (patch)
tree047b929d90077a31a39075a585ab2c3a9909a58b
parent778a877423d75f6299c57bb75c3edffd2f304e84 (diff)
downloadperlweeklychallenge-club-a60e110825aedc3295dfd1e033e2f2c6441d03c2.tar.gz
perlweeklychallenge-club-a60e110825aedc3295dfd1e033e2f2c6441d03c2.tar.bz2
perlweeklychallenge-club-a60e110825aedc3295dfd1e033e2f2c6441d03c2.zip
Challenge 336 by Jaldhar H. Vyas.
-rw-r--r--challenge-336/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-336/jaldhar-h-vyas/perl/ch-1.pl25
-rwxr-xr-xchallenge-336/jaldhar-h-vyas/perl/ch-2.pl32
-rwxr-xr-xchallenge-336/jaldhar-h-vyas/raku/ch-1.sh3
-rwxr-xr-xchallenge-336/jaldhar-h-vyas/raku/ch-2.raku27
5 files changed, 88 insertions, 0 deletions
diff --git a/challenge-336/jaldhar-h-vyas/blog.txt b/challenge-336/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..5820849dc5
--- /dev/null
+++ b/challenge-336/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2025/08/perl_weekly_challenge_week_336.html
diff --git a/challenge-336/jaldhar-h-vyas/perl/ch-1.pl b/challenge-336/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..ee2d255b22
--- /dev/null
+++ b/challenge-336/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use 5.038;
+use warnings;
+
+sub gcd($a, $b) {
+ if ($b == 0) {
+ return $a;
+ }
+
+ gcd($b, $a % $b);
+}
+
+my @ints = @ARGV;
+my %c;
+
+for my $int (@ints) {
+ $c{$int}++;
+}
+
+my $gcd = 0;
+for my $v (values %c) {
+ $gcd = gcd($gcd, $v);
+}
+
+say $gcd >= 2 ? 'true' : 'false';
diff --git a/challenge-336/jaldhar-h-vyas/perl/ch-2.pl b/challenge-336/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..61d30b88fa
--- /dev/null
+++ b/challenge-336/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+use 5.038;
+use warnings;
+
+sub sum(@elems) {
+ my $total;
+ for my $n (@elems) {
+ $total += $n;
+ }
+
+ return $total;
+}
+
+my @scores = @ARGV;
+my @previous;
+
+for my $score (@scores) {
+ if ($score eq 'C') {
+ pop @previous;
+ }
+ elsif ($score eq 'D') {
+ push @previous, 2 * $previous[-1];
+ }
+ elsif ($score eq '+') {
+ push @previous, $previous[-1] + $previous[-2];
+ }
+ else {
+ push @previous, $score;
+ }
+}
+
+say sum(@previous);
diff --git a/challenge-336/jaldhar-h-vyas/raku/ch-1.sh b/challenge-336/jaldhar-h-vyas/raku/ch-1.sh
new file mode 100755
index 0000000000..8078b5a6c8
--- /dev/null
+++ b/challenge-336/jaldhar-h-vyas/raku/ch-1.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+raku -e '@*ARGS.classify({$_},:into(my %c));say ([gcd] %c.values)>=2' "$@" \ No newline at end of file
diff --git a/challenge-336/jaldhar-h-vyas/raku/ch-2.raku b/challenge-336/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..a1594dc163
--- /dev/null
+++ b/challenge-336/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,27 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@scores
+) {
+ my @previous;
+
+ for @scores -> $score {
+ given $score {
+ when 'C' {
+ @previous.pop;
+ }
+ when 'D' {
+ @previous.push(2 * @previous[*-1]);
+ }
+ when '+' {
+ @previous.push(@previous[*-1] + @previous[*-2]);
+
+ }
+ default {
+ @previous.push($score);
+ }
+ }
+ }
+
+ say @previous.sum;
+} \ No newline at end of file