-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02.py
49 lines (36 loc) · 879 Bytes
/
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
def part1(commands):
hpos = 0
depth = 0
for c in commands:
val = int(c[1])
d = c[0]
if d == "forward":
hpos += val
elif d == "down":
depth += val
elif d == "up":
depth -= val
return hpos * depth
def part2(commands):
hpos = 0
depth = 0
aim = 0
for c in commands:
val = int(c[1])
d = c[0]
if d == "forward":
hpos += val
depth += aim * val
elif d == "down":
aim += val
elif d == "up":
aim -= val
return hpos * depth
def main():
with open("./input") as f:
commands = [list(l.strip().split(" ")) for l in f.readlines()]
print(f"part1: {part1(commands)}")
print(f"part2: {part2(commands)}")
if __name__ == "__main__":
main()