summary refs log tree commit diff homepage
path: root/2021
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-02 11:47:53 -0500
committerJune McEnroe <june@causal.agency>2021-12-02 11:47:53 -0500
commitf3ca6de686e298124f95540115604676da747436 (patch)
treeece01f64780dc36bcc4781269a439a37b4373bdc /2021
parentSolve day 2 part 1 (diff)
downloadaoc-f3ca6de686e298124f95540115604676da747436.tar.gz
aoc-f3ca6de686e298124f95540115604676da747436.zip
Solve day 2 part 2
Diffstat (limited to '2021')
-rw-r--r--2021/day02.pl6
1 files changed, 6 insertions, 0 deletions
diff --git a/2021/day02.pl b/2021/day02.pl
index 66e423a..30dc1d1 100644
--- a/2021/day02.pl
+++ b/2021/day02.pl
@@ -1,13 +1,19 @@
 use strict;
 use warnings;
 my ($depth, $pos) = (0, 0);
+my ($depth2, $pos2, $aim) = (0, 0, 0);
 while (<>) {
 	if (/forward (\d+)/) {
 		$pos += $1;
+		$pos2 += $1;
+		$depth2 += $aim * $1;
 	} elsif (/down (\d+)/) {
 		$depth += $1;
+		$aim += $1;
 	} elsif (/up (\d+)/) {
 		$depth -= $1;
+		$aim -= $1;
 	}
 }
 print $depth * $pos, "\n";
+print $depth2 * $pos2, "\n";