34 lines
812 B
Python
34 lines
812 B
Python
from aoc import AOCDay
|
|
from typing import Any, List
|
|
|
|
|
|
def follow_directions(path: List) -> (int, int, int):
|
|
pos = depth = aim = 0
|
|
for direction, value in path:
|
|
if direction == 'forward':
|
|
pos += value
|
|
depth += aim * value
|
|
elif direction == 'down':
|
|
aim += value
|
|
elif direction == 'up':
|
|
aim -= value
|
|
|
|
return pos, depth, aim
|
|
|
|
|
|
class Day(AOCDay):
|
|
test_solutions_p1 = [150]
|
|
test_solutions_p2 = [900]
|
|
|
|
def part1(self) -> Any:
|
|
path = self.getInputAsArraySplit(" ", [str, int])
|
|
pos, _, depth = follow_directions(path)
|
|
|
|
return pos * depth
|
|
|
|
def part2(self) -> Any:
|
|
path = self.getInputAsArraySplit(" ", [str, int])
|
|
pos, depth, _ = follow_directions(path)
|
|
|
|
return pos * depth
|