-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday2.py
49 lines (34 loc) · 808 Bytes
/
day2.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
import fileinput
def parse():
return [l.split() for l in fileinput.input()]
def task1(input):
horizontal = 0
depth = 0
for cmd in input:
dir = cmd[0]
val = int(cmd[1])
if dir == 'forward':
horizontal += val
if dir == 'down':
depth += val
if dir == 'up':
depth -= val
return horizontal * depth
def task2(input):
horizontal = 0
depth = 0
aim = 0
for cmd in input:
dir = cmd[0]
val = int(cmd[1])
if dir == 'forward':
horizontal += val
depth += aim * val
if dir == 'down':
aim += val
if dir == 'up':
aim -= val
return horizontal * depth
input = parse()
print(task1(input))
print(task2(input))