2021-01
This commit is contained in:
parent
6edb6c99f1
commit
703990eedc
14
2021/01/part1.pm
Normal file
14
2021/01/part1.pm
Normal 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
17
2021/01/part2.pm
Normal 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
19
2021/01/test.t
Normal 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();
|
Loading…
Reference in New Issue
Block a user