21 lines
425 B
Python
21 lines
425 B
Python
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
|