-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-dive.py
40 lines (34 loc) · 1003 Bytes
/
02-dive.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
import os
import re
FILENAME = os.path.splitext(__file__)
PUZZLE_INPUT = os.path.join('.', 'puzzle-inputs', f'{FILENAME[0]}.txt')
with open(PUZZLE_INPUT, 'r') as f:
puzzle_input = f.read().splitlines()
def solution_one():
horizontal = 0
depth = 0
number = re.compile(r"\d+")
for direction in puzzle_input:
amount = int(number.search(direction).group())
if direction[0] == "f":
horizontal += amount
elif direction[0] == "d":
depth += amount
else:
depth -= amount
return horizontal * depth
def solution_two():
horizontal = 0
aim = 0
depth = 0
number = re.compile(r"\d+")
for direction in puzzle_input:
amount = int(number.search(direction).group())
if direction[0] == "f":
horizontal += amount
depth += aim * amount
elif direction[0] == "d":
aim += amount
else:
aim -= amount
return horizontal * depth