adventofcode/2020/16/part1.pm
2021-12-05 11:51:21 -05:00

28 lines
506 B
Perl

package part1;
use 5.20.0;
use warnings;
use List::AllUtils qw/ sum /;
use Range::Merge qw/ merge /;
use experimental qw/ signatures postderef /;
sub numbers_out_of_range($input) {
my $ranges = merge([ map { [ split '-' ] } $input =~ /(\d+-\d+)/g]);
$input =~ /nearby tickets:(.*)/s;
my @tickets = $1 =~ /(\d+)/g;
return grep {
not( $_ >= $ranges->[0][0] and $_ <= $ranges->[0][1])
} @tickets;
}
sub solution($input) {
return sum numbers_out_of_range($input);
}
1;