aoc2021/day02.py
2021-12-09 06:41:55 +01:00

34 lines
818 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]
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