adventofcode/2024/02/Part2.pm

26 lines
411 B
Perl
Raw Normal View History

2024-12-04 20:46:05 +00:00
use lib qw/ . /;
use Part1;
package Day2::Part2;
use 5.36.0;
use List::Util qw/ sum pairmap /;
use List::MoreUtils qw/ part zip /;
sub is_safe_dampened(@report) {
for my $i ( 0..$#report) {
my @copy = @report;
splice @copy, $i, 1;
return 1 if Day2::Part1::is_safe(@copy);
}
return 0;
}
sub solve(@reports) {
return sum map { is_safe_dampened(@$_) } @reports;
}
1;