From f3c3fa9b94bc61b90a029bb74c98215b45c5be15 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Fri, 3 Dec 2021 09:41:56 +0100 Subject: Day 2 part 2 --- day2/__init__.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'day2') diff --git a/day2/__init__.py b/day2/__init__.py index e16787f..14229a9 100644 --- a/day2/__init__.py +++ b/day2/__init__.py @@ -33,12 +33,20 @@ class AssignmentOne(Assignment): return self.depth * self.horizontal - class AssignmentTwo(Assignment): + aim = 0 + depth = 0 + horizontal = 0 + def run(self, input: List) -> int: - new_input = [ - input[i - 2] + input[i - 1] + input[i] - for i in range(2, len(input)) - ] + for instruction in input: + match instruction.direction: + case 'forward': + self.horizontal += instruction.steps + self.depth += instruction.steps * self.aim + case 'up': + self.aim -= instruction.steps + case 'down': + self.aim += instruction.steps - return AssignmentOne(path='').run(new_input) + return self.depth * self.horizontal -- cgit v1.2.3