aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetilS <kjetilskotheim@gmail.com>2024-07-07 22:14:17 +0200
committerKjetilS <kjetilskotheim@gmail.com>2024-07-07 22:14:17 +0200
commit3417cbc794bf45ba6c48a905554933c5f37fb77c (patch)
tree83d81d2dd2b2e857a7293470ce425bcc8664a06d
parent922dcd71efb67127954deab2dc357b456f4ed6a6 (diff)
downloadperlweeklychallenge-club-3417cbc794bf45ba6c48a905554933c5f37fb77c.tar.gz
perlweeklychallenge-club-3417cbc794bf45ba6c48a905554933c5f37fb77c.tar.bz2
perlweeklychallenge-club-3417cbc794bf45ba6c48a905554933c5f37fb77c.zip
https://theweeklychallenge.org/blog/perl-weekly-challenge-276/
-rw-r--r--challenge-276/kjetillll/perl/ch-1.pl15
-rw-r--r--challenge-276/kjetillll/perl/ch-2.pl12
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-276/kjetillll/perl/ch-1.pl b/challenge-276/kjetillll/perl/ch-1.pl
new file mode 100644
index 0000000000..5ffbce9b13
--- /dev/null
+++ b/challenge-276/kjetillll/perl/ch-1.pl
@@ -0,0 +1,15 @@
+use strict; use warnings; use Test::More tests=>3;
+
+sub complete_day_pair_count {
+ my $pairs = 0;
+ "@_" =~ /
+ \b(\d+)\b .+ \b(\d+)\b
+ (??{ $pairs+=($1+$2)%24==0;'^' })
+ /x;
+ $pairs
+}
+
+is complete_day_pair_count( @{ $$_{input} } ), $$_{output}
+ for { input => [12, 12, 30, 24, 24], output => 2 },
+ { input => [72, 48, 24, 5 ], output => 3 },
+ { input => [12, 18, 24 ], output => 0 };
diff --git a/challenge-276/kjetillll/perl/ch-2.pl b/challenge-276/kjetillll/perl/ch-2.pl
new file mode 100644
index 0000000000..84e1565657
--- /dev/null
+++ b/challenge-276/kjetillll/perl/ch-2.pl
@@ -0,0 +1,12 @@
+use strict; use warnings; use Test::More tests => 2; use List::Util qw(max sum);
+
+sub maximum_frequency {
+ my %freq;
+ $freq{ $_ }++ for @_;
+ my $max_freq = max( values %freq );
+ sum( map $freq{$_}, grep $freq{$_} == $max_freq, keys%freq )
+}
+
+is maximum_frequency( @{ $$_{input} } ), $$_{output}
+ for { input => [1, 2, 2, 4, 1, 5], output=> 4 },
+ { input => [1, 2, 3, 4, 5 ], output=> 5 };