A random walker is an agent that randomly decides which direction to go at each step.
We want a function that given the original coordinates of the random walker, and a string with the direction to take at each step, computes the final coordinates of the walker.
The string
contains only the characters ’N’, ’S’,
’E’, and ’W’. North (’N’) means
moving up one position in the
axis, and South (’S’) moving down one position in
.
Similarly, East (’E’) and West (’W’)
correspond to moving along the
axis one position right or left, respectively.
For instance if the walker starts at position A
in the picture below, and the string with the steps taken is
’NEENWNWWS’, the walker will follow the path through positions marked
with stars in the picture, and the final position will be B
.
|
4-| *--*--*
| | |
3-| B *--*
| |
2-| *--*--*
| |
1-| A
|
0 +--|--|--|--|--|--|--
0 1 2 3 4 5 6
Important: Only the function is expected. If you
submission includes a main program, it has to be either commented out,
or under the condition if __name__ == "__main__":
>>> walker(4, 1, 'NEENWNWWS') (3, 3) >>> walker(3, 5, 'NESW') (3, 5) >>> walker(0, 4, 'SSSSEWEWNNNN') (0, 4) >>> walker(0, 0, 'SWSWNES') (-1, -2) >>> walker(6, 3, '') (6, 3)