summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-12-15 20:28:53 -0500
committerJune McEnroe <june@causal.agency>2023-12-15 20:35:04 -0500
commitc2219772863be4c5d66d88617c2a65b7ed0a4e76 (patch)
tree9676378bf0c0d01f949dc5c9a789cd9845d62374
parentSolve day 9 part 1 (diff)
downloadaoc-c2219772863be4c5d66d88617c2a65b7ed0a4e76.tar.gz
aoc-c2219772863be4c5d66d88617c2a65b7ed0a4e76.zip
Solve day 9 part 2
Diffstat (limited to '')
-rw-r--r--2023/day09.pl13
1 files changed, 9 insertions, 4 deletions
diff --git a/2023/day09.pl b/2023/day09.pl
index 5ec28b2..c9814c9 100644
--- a/2023/day09.pl
+++ b/2023/day09.pl
@@ -13,16 +13,21 @@ sub extrapolate {
 	while (any { $_ != 0 } @{$diffs[0]}) {
 		unshift @diffs, [diff(@{$diffs[0]})];
 	}
+	unshift @{$diffs[0]}, 0;
 	push @{$diffs[0]}, 0;
 	for (1 .. $#diffs) {
-		push @{$diffs[$_]}, $diffs[$_-1]->[-1] + $diffs[$_]->[-1];
+		unshift @{$diffs[$_]}, $diffs[$_][0] - $diffs[$_-1][0];
+		push @{$diffs[$_]}, $diffs[$_-1][-1] + $diffs[$_][-1];
 	}
-	$diffs[-1]->[-1];
+	($diffs[-1][0], $diffs[-1][-1]);
 }
-my $sum = 0;
+my ($sum, $sum2) = (0, 0);
 while (<>) {
 	chomp;
 	my @history = split(/ /);
-	$sum += extrapolate(@history);
+	my ($first, $last) = extrapolate(@history);
+	$sum += $last;
+	$sum2 += $first;
 }
 print $sum, "\n";
+print $sum2, "\n";
10-27 01:22:30 -0400'>2019-10-27Add reload cmd to rc scriptJune McEnroe 2019-10-27Reload certificate on SIGUSR1June McEnroe 2019-10-27Drop clients on zero-length readsJune McEnroe 2019-10-27Explicitly tls_handshake new clientsJune McEnroe 2019-10-26Document rationaleJune McEnroe 2019-10-26Handle nick collisionJune McEnroe 2019-10-26Wait for AUTHENTICATE + from serverJune McEnroe 2019-10-26Respond to PING with same parameterJune McEnroe 2019-10-26Add undocumented flag to disable verificationJune McEnroe 2019-10-26Do not require RPL_ISUPPORT for stateReadyJune McEnroe 2019-10-26Implement graceful shutdownJune McEnroe 2019-10-26Require PASS before USERJune McEnroe 2019-10-26Track channel topicsJune McEnroe 2019-10-26Set AWAY when no clients are connectedJune McEnroe 2019-10-26Add flags to request TOPIC and NAMES on client connectJune McEnroe 2019-10-26OopsJune McEnroe 2019-10-26Disconnect client on unknown commandJune McEnroe 2019-10-26Allow reading sensitive information from filesJune McEnroe 2019-10-26Add rc scriptJune McEnroe 2019-10-25Add install and uninstall targetsJune McEnroe 2019-10-25Expand documentationJune McEnroe 2019-10-25Add AGPLv3 notice on client registrationJune McEnroe 2019-10-25Rename project pounceJune McEnroe