diff options
| author | 2021-12-03 09:41:56 +0100 | |
|---|---|---|
| committer | 2021-12-03 09:41:56 +0100 | |
| commit | f3c3fa9b94bc61b90a029bb74c98215b45c5be15 (patch) | |
| tree | 0d71acfcd9e989ca9161e6d1a887d34792659434 /day2/__init__.py | |
| parent | 824eaed0232ca337ff67f0cf0269f474e0471e2f (diff) | |
| download | 2021-f3c3fa9b94bc61b90a029bb74c98215b45c5be15.tar.gz 2021-f3c3fa9b94bc61b90a029bb74c98215b45c5be15.tar.bz2 2021-f3c3fa9b94bc61b90a029bb74c98215b45c5be15.zip | |
Day 2 part 2
Diffstat (limited to 'day2/__init__.py')
| -rw-r--r-- | day2/__init__.py | 20 |
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 | |||
| 37 | class AssignmentTwo(Assignment): | 36 | class 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 |
