From b19d5feac5278f22a87eaf3fd77be4674e41e185 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 2 Dec 2021 11:44:01 -0500 Subject: Solve day 2 part 1 --- 2021/day02.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 2021/day02.pl (limited to '2021/day02.pl') 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"; -- cgit 1.4.1