summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-01 13:32:26 -0500
committerJune McEnroe <june@causal.agency>2021-12-01 13:32:26 -0500
commit0885e8011c44dbd62dc24a26caa5e7b588eb7e2c (patch)
treee9bf02211000764bfc3e1c7beb5de4e3e44a4f22
parentSolve day 1 part 1 (diff)
downloadaoc-0885e8011c44dbd62dc24a26caa5e7b588eb7e2c.tar.gz
aoc-0885e8011c44dbd62dc24a26caa5e7b588eb7e2c.zip
Solve day 1 part 2
-rw-r--r--2021/day01.pl13
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";
> 2019-09-12Consume entire bodyJune McEnroe 2019-09-10Add title -v flagJune McEnroe 2019-09-10Use curl error bufferJune McEnroe 2019-09-10Set Accept-Encoding in titleJune McEnroe 2019-09-08Set title User-AgentJune McEnroe 2019-09-07Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe