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

38 lines
610 B
Perl

package part1;
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
sub solution($n, $entries) {
my @numbers = split "\n", $entries;
my %seen;
my @previous;
# prime the pump
while( @previous < $n ) {
my $n = shift @numbers;
$seen{$n + $_}++ for @previous;
push @previous, $n;
}
while(my $next = shift @numbers) {
return $next unless $seen{$next};
my $goner = shift @previous;
$seen{$goner + $_}-- for @previous;
$seen{$next + $_}++ for @previous;
push @previous, $next;
}
}
1;