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
commitc2de1081fd0aeb46d22c5d6b9f71bbb28a3fbc72 (patch)
tree8e67168124684d20eda44b29685b39ebef741f0e
parentSolve day 1 part 2 (diff)
downloadaoc-c2de1081fd0aeb46d22c5d6b9f71bbb28a3fbc72.tar.gz
aoc-c2de1081fd0aeb46d22c5d6b9f71bbb28a3fbc72.zip
Solve day 2 part 1
Diffstat (limited to '')
-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";