aboutsummaryrefslogtreecommitdiff
path: root/challenge-276
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2024-07-02 10:50:09 +0000
committerNiels van Dijke <perlboy@cpan.org>2024-07-02 10:50:09 +0000
commite04f0ca389573900a93da9b7ea35682d0641dfc8 (patch)
tree50213c2819c03faea3799f30887d1b6c3920ceb4 /challenge-276
parentf18cb7a95e46b9ded70a2d1d932d0bb7b1772a67 (diff)
downloadperlweeklychallenge-club-e04f0ca389573900a93da9b7ea35682d0641dfc8.tar.gz
perlweeklychallenge-club-e04f0ca389573900a93da9b7ea35682d0641dfc8.tar.bz2
perlweeklychallenge-club-e04f0ca389573900a93da9b7ea35682d0641dfc8.zip
w276 - Task 1 & 2
Diffstat (limited to 'challenge-276')
-rwxr-xr-xchallenge-276/perlboy1967/perl/ch1.pl39
-rwxr-xr-xchallenge-276/perlboy1967/perl/ch2.pl38
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-276/perlboy1967/perl/ch1.pl b/challenge-276/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..9ff82133f6
--- /dev/null
+++ b/challenge-276/perlboy1967/perl/ch1.pl
@@ -0,0 +1,39 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 276
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-276
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Complete Day
+Submitted by: Mohammad Sajid Anwar
+
+You are given an array of integers, @hours.
+
+Write a script to return the number of pairs that forms a complete day.
+
+|| A complete day is defined as a time duration that is an exact multiple
+|| of 24 hours.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0 qw(-no_srand);
+use DDP;
+
+use Algorithm::Combinatorics qw(combinations);
+
+sub completeDay (@hours) {
+ grep { $_ % 24 == 0 } map { $$_[0] + $$_[1] } combinations(\@hours,2);
+}
+
+is(completeDay(12,12,30,24,24),2);
+is(completeDay(72,48,24,5),3);
+is(completeDay(12,18,24),0);
+
+done_testing;
diff --git a/challenge-276/perlboy1967/perl/ch2.pl b/challenge-276/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..d19bebae7e
--- /dev/null
+++ b/challenge-276/perlboy1967/perl/ch2.pl
@@ -0,0 +1,38 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 276
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-276
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Maximum Frequency
+Submitted by: Mohammad Sajid Anwar
+
+You are given an array of positive integers, @ints.
+
+Write a script to return the total number of elements in the given
+array which have the highest frequency.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0 qw(-no_srand);
+
+use List::AllUtils qw(sum0);
+
+sub maximumFrequency (@ints) {
+ my ($m,%f) = (0);
+ map {$f{$_}++; $m++ if $f{$_} > $m} @ints;
+ $m * scalar grep { $_ == $m } values %f;
+}
+
+is(maximumFrequency(1,2,2,4,1,5),4);
+is(maximumFrequency(1,2,3,4,5),5);
+is(maximumFrequency(1,1,3,3,5,5,7),6);
+
+done_testing;