robot
unknown
python
4 years ago
477 B
4
Indexable
def parse_commands(filename):
x = y = 0
coordinate_by = lambda direction, distance, x, y: {
'North': (x, y + distance),
'East' : (x + distance, y),
'South': (x, y - distance),
'West' : (x - distance, y),
}.get(direction)
with open(filename) as lines:
for line in lines:
direction, distance = line.split()
x, y = coordinate_by(direction, int(distance), x, y)
return x, y
Editor is loading...