Oh no, I am lost on the way to finding the great treasures of Marakov! And all I have are these useless instructions that look like S10R10D30
... I have no idea what they mean! Can you help me?
Challenge
Given directions consisting of N E S W U D L R 1 2 3 4 5 6 7 8 9 0
, output how far I will be from where I started when I follow those directions (i.e. Euclidean Distance).
N E S W
refer to me turning North, East, South, and West;
U D L R
refer to me turning Up, Down, Left, and Right (So NR
is the same as E
, and so is SL
; SLL
is the same as N
). Up means keep going forward; Down means turn around.
After each letter direction will be a number, which is how far I will go in that direction. N10E20
means go North 10 units, then turn East, and go East 20 units.
Input Details
- Input will always start with one of
NESW
(so blank input need not be accounted for). - Two letter instructions in a row are allowed.
NE
should be interpreted, "Turn North, then immediately turn East". It's the same as justE
.SLL
is "Turn South, then immediately turn Left twice". It's the same asN
. - All numbers will be integers (note how
.
isn't in the character set) - Input will only consist of
NESWUDLR1234567890
(If it needs something else, like '\0' in C; or if your language's input functions has a trailing newline, or something, that's fine.)
Output
- The norm.
- If using a function, should output a numeric datatype or a string.
- Must be accurate to 3 decimal places.
Test Cases
N10
:10
N10E10
:14.1421
N10S10
:0
NSEWUDLR10
:10
N100RR20E300D40L12
:268.7452
ERR10LL20UN30D100
:70.71067
The unimaginative Python program I used to make these.
Winning
This is codegolf, so lowest bytes after a week wins!
NESWUDLR1234567890
? \$\endgroup\$