summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-02 11:44:01 -0500
committerJune McEnroe <june@causal.agency>2021-12-02 11:44:01 -0500
commitb19d5feac5278f22a87eaf3fd77be4674e41e185 (patch)
tree702726bd751a431d7500ac1ce2395d57eaae433b
parentSolve day 1 part 2 (diff)
downloadaoc-b19d5feac5278f22a87eaf3fd77be4674e41e185.tar.gz
aoc-b19d5feac5278f22a87eaf3fd77be4674e41e185.zip
Solve day 2 part 1
-rw-r--r--2021/day02.pl13
1 files changed, 13 insertions, 0 deletions
diff --git a/2021/day02.pl b/2021/day02.pl
new file mode 100644
index 0000000..66e423a
--- /dev/null
+++ b/2021/day02.pl
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+my ($depth, $pos) = (0, 0);
+while (<>) {
+	if (/forward (\d+)/) {
+		$pos += $1;
+	} elsif (/down (\d+)/) {
+		$depth += $1;
+	} elsif (/up (\d+)/) {
+		$depth -= $1;
+	}
+}
+print $depth * $pos, "\n";