Untitled
unknown
python
4 years ago
474 B
9
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, yEditor is loading...