Advent-of-Code/2021/2/main2.py

21 lines
425 B
Python
Raw Permalink Normal View History

2021-12-06 14:56:21 -05:00
aim = 0
x = 0 # horizontal position
d = 0 # depth
with open('data', 'r') as fp:
for line in fp:
data = line.split()
if(data[0] == 'forward'):
x = x + int(data[1])
d = d + aim * int(data[1])
elif(data[0] == 'down'):
aim = aim + int(data[1])
else:
aim = aim - int(data[1])
print " x: ", x
print " d: ", d
print "aim: ", aim
print " : ", x * d