AdventOfCode/2021/day2/day2.py

39 lines
731 B
Python

with open("day2_data.txt", "r") as f:
x = [[ j for j in x.split() ] for x in f]
horizontal=0
depth=0
#print(x)
direction=""
for i in range(len(x)):
direction=x[i][0]
temp=int(x[i][1])
if(direction=="up"):
#print("up "+ str(temp))
depth-=temp
elif(direction=="down"):
#print("down " + str(temp))
depth+=temp
elif(direction=="forward"):
#print("forward " + str(temp))
horizontal+=temp
else:
print("ERROR")
print("horizontal: "+str(horizontal))
print("depth: " + str(depth))
print("result: " + str(horizontal*depth))
#print(direction + " " + str(temp))
#print(temp,end=" ")
#print("("+str(type(temp))+")",end=" ")