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