diff options
| -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 }; |
