-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay02.py
More file actions
43 lines (33 loc) · 976 Bytes
/
Day02.py
File metadata and controls
43 lines (33 loc) · 976 Bytes
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
from Utility import *
filePath = 'input/day02/part1.txt'
def solvePart1():
inputLines = getLinesFromFile(filePath)
x, y = 0, 0
for line in inputLines:
if(line.startswith('forward')):
x += int(line.split(' ')[1])
if(line.startswith('down')):
y += int(line.split(' ')[1])
if(line.startswith('up')):
y -= int(line.split(' ')[1])
result = x * y
print('Solution to part1:')
print(result)
def solvePart2():
inputLines = getLinesFromFile(filePath)
x, y, aim = 0, 0, 0
for line in inputLines:
value = int(line.split(' ')[1])
if(line.startswith('forward')):
x += value
y += aim * value
if(line.startswith('down')):
aim += value
if(line.startswith('up')):
aim -= value
result = x * y
print('Solution to part2:')
print(result)
if(__name__ == '__main__'):
solvePart1()
solvePart2()