From 0885e8011c44dbd62dc24a26caa5e7b588eb7e2c Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 1 Dec 2021 13:32:26 -0500 Subject: Solve day 1 part 2 --- 2021/day01.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to '2021') 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"; -- cgit 1.4.1