diff options
-rw-r--r-- | 2021/day01.pl | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/2021/day01.pl b/2021/day01.pl index f4ab273..ffc5949 100644 --- a/2021/day01.pl +++ b/2021/day01.pl @@ -1,6 +1,15 @@ -my $last, $incs; +use strict; +use warnings; +my ($last, @window, $incs, $incs2); while (<>) { $incs++ if ($last && $_ > $last); $last = $_; + if (scalar @window == 3) { + my $prev = $window[0] + $window[1] + $window[2]; + my $next = $window[1] + $window[2] + $_; + $incs2++ if ($next > $prev); + shift @window; + } + push @window, $_; } -print "$incs\n"; +print "$incs\n$incs2\n"; |