diff options
| author | June McEnroe <june@causal.agency> | 2021-12-01 13:32:26 -0500 |
|---|---|---|
| committer | June McEnroe <june@causal.agency> | 2021-12-01 13:32:26 -0500 |
| commit | f1dd36fde2d5387db2462b72637d990c3cb9c9de (patch) | |
| tree | a9bf1c52f8554ca99c9873dd482044803eb29b5d | |
| parent | Solve day 1 part 1 (diff) | |
| download | aoc-f1dd36fde2d5387db2462b72637d990c3cb9c9de.tar.gz aoc-f1dd36fde2d5387db2462b72637d990c3cb9c9de.zip | |
Solve day 1 part 2
| -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"; |