-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02.py
executable file
·49 lines (37 loc) · 1.15 KB
/
day02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python3
### local imports
import utils
@utils.part1
def part1(puzzleInput: str):
# Parse the list of instructions in tuple pairs of a string and int
instructions: list[tuple[str, int]] = [
(line.split(" ")[0], int(line.split(" ")[1]))
for line in puzzleInput.strip().splitlines()
]
distance: int = 0
depth: int = 0
for direction, magnitude in instructions:
if direction == "forward":
distance += magnitude
elif direction == "down":
depth += magnitude
elif direction == "up":
depth -= magnitude
utils.printAnswer(distance * depth)
# Pass parsed instructions to part 2
return instructions
@utils.part2
def part2(_, instructions: list[tuple[str, int]]):
distance: int = 0
depth: int = 0
aim: int = 0
for direction, magnitude in instructions:
if direction == "forward":
distance += magnitude
depth += aim * magnitude
elif direction == "down":
aim += magnitude
elif direction == "up":
aim -= magnitude
utils.printAnswer(distance * depth)
utils.start()