18 lines
345 B
Python
18 lines
345 B
Python
|
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])
|
||
|
elif(data[0] == 'down'):
|
||
|
d = d + int(data[1])
|
||
|
else:
|
||
|
d = d - int(data[1])
|
||
|
|
||
|
print "x: ", x
|
||
|
print "d: ", d
|
||
|
print " : ", x * d
|