from dataclasses import dataclass from typing import Iterator, List from aoc import BaseAssignment @dataclass class Instruction: direction: str steps: int class Assignment(BaseAssignment): def parse_item(self, item: str) -> Instruction: direction, steps = item.split(' ') return Instruction(direction=direction, steps=int(steps)) def read_input(self, example = False) -> List[Instruction]: return list(super().read_input(example)) class AssignmentOne(Assignment): example_result = 150 depth = 0 horizontal = 0 def run(self, input: List[Instruction]) -> int: for instruction in input: match instruction.direction: case 'forward': self.horizontal += instruction.steps case 'up': self.depth -= instruction.steps case 'down': self.depth += instruction.steps return self.depth * self.horizontal class AssignmentTwo(Assignment): example_result = 900 aim = 0 depth = 0 horizontal = 0 def run(self, input: List) -> int: 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 self.depth * self.horizontal