44 lines
962 B
Python
44 lines
962 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
|
||
|
aim=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))
|
||
|
aim-=temp
|
||
|
#depth-=temp
|
||
|
elif(direction=="down"):
|
||
|
#print("down " + str(temp))
|
||
|
aim+=temp
|
||
|
#depth+=temp
|
||
|
elif(direction=="forward"):
|
||
|
#print("forward " + str(temp))
|
||
|
depth = depth + (aim * temp)
|
||
|
horizontal+=temp
|
||
|
direction="forw"
|
||
|
else:
|
||
|
print("ERROR")
|
||
|
print(direction+" "+str(temp)+ "\t horizontal: " + str(horizontal) + "\t depth: " + str(depth) + "\t\t aim: " + str(aim))
|
||
|
|
||
|
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=" ")
|