adventofcode/2020/09/part2.pm
2021-12-05 11:51:21 -05:00

36 lines
546 B
Perl

package part2;
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
use List::AllUtils qw/ minmax sum /;
sub solution($target, $entries) {
my @numbers = split "\n", $entries;
my $sum = 0;
my @seq;
while( @numbers ) {
while( $sum < $target ) {
push @seq, shift @numbers;
$sum += $seq[-1];
}
while( $sum > $target ) {
$sum -= shift @seq;
}
if( $sum == $target ) {
return sum minmax @seq;
}
}
}
1;