aoc2021/day02.py

34 lines
839 B
Python

from tools.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, 2120749]
test_solutions_p2 = [900, 2138382217]
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