This commit is contained in:
Yanick Champoux 2021-12-05 11:44:23 -05:00
parent 6edb6c99f1
commit 703990eedc
3 changed files with 50 additions and 0 deletions

14
2021/01/part1.pm Normal file
View File

@ -0,0 +1,14 @@
package part1;
use 5.34.0;
use warnings;
use experimental 'signatures';
use List::AllUtils qw/ sum /;
sub solution(@list) {
return sum map { $list[$_] > $list[$_-1] } 1..$#list;
}
1;

17
2021/01/part2.pm Normal file
View File

@ -0,0 +1,17 @@
package part2;
use 5.34.0;
use warnings;
use experimental 'signatures';
use List::AllUtils qw/ sum /;
require './part1.pm';
sub solution(@list) {
return part1::solution(
map { my $i = $_; sum map { $list[$i+$_] } 0..2 } 0..$#list-2
);
}
1;

19
2021/01/test.t Normal file
View File

@ -0,0 +1,19 @@
use 5.34.0;
use Test2::V0;
use Path::Tiny;
require './part1.pm';
require './part2.pm';
my @list = path('./input')->lines;
subtest part1 => sub {
is part1::solution( @list ) => 1602;
};
subtest part2 => sub {
is part2::solution(@list) => 1633;
};
done_testing();