summaryrefslogtreecommitdiffstats
path: root/day2/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'day2/__init__.py')
-rw-r--r--day2/__init__.py20
1 files changed, 14 insertions, 6 deletions
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):
33 return self.depth * self.horizontal 33 return self.depth * self.horizontal
34 34
35 35
36
37class AssignmentTwo(Assignment): 36class AssignmentTwo(Assignment):
37 aim = 0
38 depth = 0
39 horizontal = 0
40
38 def run(self, input: List) -> int: 41 def run(self, input: List) -> int:
39 new_input = [ 42 for instruction in input:
40 input[i - 2] + input[i - 1] + input[i] 43 match instruction.direction:
41 for i in range(2, len(input)) 44 case 'forward':
42 ] 45 self.horizontal += instruction.steps
46 self.depth += instruction.steps * self.aim
47 case 'up':
48 self.aim -= instruction.steps
49 case 'down':
50 self.aim += instruction.steps
43 51
44 return AssignmentOne(path='').run(new_input) 52 return self.depth * self.horizontal