Finding a treasure hidden by pirates is really easy. Everything you need for this is a map. It is widely known that pirates draw maps by hand and describe the algorithm to find a place in the following way: "Stand near a lone palm tree, do 30 steps towards the forest, 15 towards the lake, ..."
A journey through such route is usually a great opportunity to see the scenery... However, nowadays nobody has time for that. That's why treasure seekers have asked you to write a program that would determine the exact location of a treasure using a given map.
Input
The input consists of multiple instructions <Direction> <Distance>
, separated with commas (that are followed by one whitespace each).
Direction is one of the following:
N
- North, S
- South, E
- East, W
- West,
NE
- Northeast, NW
- Northwest, SE
- Southeast, SW
- Southwest.
Distance is an integer (1 to 1000).
Output
The result is the coordinates where you end up after finishing the instructions, with three decimal places, separated with a comma and a whitespace. Start location has zero coordinates (0, 0).
The first coordinate is X (East means coordinates larger than zero, West means less than zero).
The second coordinate is Y (North means more than zero, South means less than zero).
Examples
1. N 3, E 1, N 1, E 3, S 2, W 1
3.000, 2.000
2. NW 10
-7.071, 7.071
3. NE 42, NW 42, SE 42, SW 42
0.000, 0.000
Source (in Ukrainian). Input format is different there.
-3.000, 2.000
. \$\endgroup\$(print (word (form xcor 4 3) ",) (form ycor 4 3))
. But I'm not sure how easy parsing the input would be. \$\endgroup\$