aboutsummaryrefslogtreecommitdiff
path: root/challenge-276
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-07 23:17:40 +0100
committerGitHub <noreply@github.com>2024-07-07 23:17:40 +0100
commit088b6d4bf7c2a5dcd9d6215844626321ab20d3cb (patch)
tree52aec8fc4fffd8310231941ad96e3352a6df53e4 /challenge-276
parent8c75e597e3543fd9af745e0ba2cd102a83eb4d36 (diff)
parent27148c0974bce996e46aa44c5ead7accdf80a4db (diff)
downloadperlweeklychallenge-club-088b6d4bf7c2a5dcd9d6215844626321ab20d3cb.tar.gz
perlweeklychallenge-club-088b6d4bf7c2a5dcd9d6215844626321ab20d3cb.tar.bz2
perlweeklychallenge-club-088b6d4bf7c2a5dcd9d6215844626321ab20d3cb.zip
Merge pull request #10387 from jaldhar/challenge-276
Challenge 276 by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-276')
-rw-r--r--challenge-276/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-276/jaldhar-h-vyas/perl/ch-1.pl35
-rwxr-xr-xchallenge-276/jaldhar-h-vyas/perl/ch-2.pl24
-rwxr-xr-xchallenge-276/jaldhar-h-vyas/raku/ch-1.sh3
-rwxr-xr-xchallenge-276/jaldhar-h-vyas/raku/ch-2.raku25
5 files changed, 88 insertions, 0 deletions
diff --git a/challenge-276/jaldhar-h-vyas/blog.txt b/challenge-276/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..816edc923d
--- /dev/null
+++ b/challenge-276/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2024/07/perl_weekly_challenge_week_276.html
diff --git a/challenge-276/jaldhar-h-vyas/perl/ch-1.pl b/challenge-276/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..1cfe9a0de9
--- /dev/null
+++ b/challenge-276/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+use v5.38;
+
+sub combinations($listref, $length) {
+ my @list = @{$listref};
+
+ if ($length <= 1) {
+ return map [$_], @list;
+ }
+
+ my @combos;
+
+ for (my $i = 0; $i + $length <= scalar @list; $i++) {
+ my $val = $list[$i];
+ my @rest = @list[$i + 1 .. $#list];
+ for my $c (combinations(\@rest, $length - 1)) {
+ push @combos, [$val, @{$c}] ;
+ }
+ }
+
+ return @combos;
+}
+
+sub sum {
+ my $total;
+ for my $n (@_) {
+ $total += $n;
+ }
+
+ return $total;
+}
+
+my @hours = @ARGV;
+
+ say scalar grep { sum(@{$_}) % 24 == 0 } combinations(\@hours, 2);
diff --git a/challenge-276/jaldhar-h-vyas/perl/ch-2.pl b/challenge-276/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..d589b05412
--- /dev/null
+++ b/challenge-276/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use v5.38;
+
+my @ints = @ARGV;
+
+my %freq;
+
+for my $int (@ints) {
+ $freq{$int}++;
+}
+
+my $max = 0;
+my $output = 0;
+
+while (my ($k, $v) = each %freq) {
+ if ($v > $max) {
+ $max = $v;
+ $output = 1;
+ } elsif ($v == $max) {
+ $output++;
+ }
+}
+
+say $output;
diff --git a/challenge-276/jaldhar-h-vyas/raku/ch-1.sh b/challenge-276/jaldhar-h-vyas/raku/ch-1.sh
new file mode 100755
index 0000000000..7648beaba0
--- /dev/null
+++ b/challenge-276/jaldhar-h-vyas/raku/ch-1.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+raku -e '@*ARGS.combinations(2).grep({$_.sum%%24}).elems.say' "$@"
diff --git a/challenge-276/jaldhar-h-vyas/raku/ch-2.raku b/challenge-276/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..f92a1efcb3
--- /dev/null
+++ b/challenge-276/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ *@ints
+) {
+ my %freq;
+
+ for @ints -> $int {
+ %freq{$int}++;
+ }
+
+ my $max = 0;
+ my $output = 0;
+
+ for %freq.kv -> $k, $v {
+ if $v > $max {
+ $max = $v;
+ $output = 1;
+ } elsif $v == $max {
+ $output++;
+ }
+ }
+
+ say $output;
+} \ No newline at end of file