diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-07 21:30:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-07 21:30:11 +0100 |
| commit | f522709dab87be43f3b916321df600b44c3fd3c3 (patch) | |
| tree | 449c74854feaaff90dbbbc5490eacf0eabb50c33 | |
| parent | ea198221d423736cc54a4dd9d2bcfdff9a487fde (diff) | |
| parent | d6504cf10304bd3fbf559c62a793848342dd98b4 (diff) | |
| download | perlweeklychallenge-club-f522709dab87be43f3b916321df600b44c3fd3c3.tar.gz perlweeklychallenge-club-f522709dab87be43f3b916321df600b44c3fd3c3.tar.bz2 perlweeklychallenge-club-f522709dab87be43f3b916321df600b44c3fd3c3.zip | |
Merge pull request #10380 from kjetillll/challenge-276-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-276/
| -rw-r--r-- | challenge-276/kjetillll/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-276/kjetillll/perl/ch-2.pl | 12 |
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..5aafa7b947 --- /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..ef31b9345e --- /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 $_, grep $_ == $max_freq, values %freq ) +} + +is maximum_frequency( @{ $$_{input} } ), $$_{output} + for { input => [1, 2, 2, 4, 1, 5], output=> 4 }, + { input => [1, 2, 3, 4, 5 ], output=> 5 }; |
