Introduction
"Yarr!! We had a laddie who called himself a "programmer" make a map t' our hidden treasure! But 'tis written wit' weird numbers 'n letters! "E5, N2, E3"... what does it even mean? Madness! Can't even scribe a proper treasure map, t' useless cretin. Fix it fer us! We'll gift ye a share o' t' treasure!"
Challenge Description
A group of pirates are having trouble reading a treasure map. Can you write a program to convert it into a more... piratey form?
As input, you'll receive the original treasure map. It's a list of comma separated strings, each string which consists of a letter portion (which tells the pirates which direction they need to walk in), and a number portion (which tells the pirates how many steps to take in that direction). For instance, the following treasure map:
E2,N4,E5,S2,W1,S3
would mean, "walk two steps to the east, walk four steps to the north, walk five steps to the east, walk two steps to the south, walk one step to the west, then walk three steps to the south."
As output, you'll output the map in a graphical form, using the characters >
, ^
, v
, and <
as pointers. Here's the output for the above input:
>>>>>v
^ v
^ v<
^ v
>>^ X
Notice that we've replaced the last step to the south with an X
instead. This is because the last step is where the treasure is, and as we all know, pirates must have an X on their treasure maps, otherwise they won't know how to read it.
By the way, the map won't ever cross itself, so you don't need to worry about dealing with overlaps. Also, you are allowed to have a trailing new line at the end of the output.
Sample Inputs and Outputs
S5,W2
v
v
v
v
v
X<
N1,E1,S1,E1,N1,E1,S2
>v>v
^>^X
N1
X
N6,E6,S6,W5,N5,E4,S4,W3,N3,E2,S2,W1,N2
>>>>>>v
^>>>>vv
^^>>vvv
^^^Xvvv
^^^^<vv
^^^<<<v
^^<<<<<
E21,S2
>>>>>>>>>>>>>>>>>>>>>v
X
N12,E11,S12,W2,N4
>>>>>>>>>>>v
^ v
^ v
^ v
^ v
^ v
^ v
^ v
^ v
^ X v
^ ^ v
^ ^ v
^ ^<<
X
should mark the step after the last move, like all other moves are counted. Imagine the last step is N3: you walk three steps to the north and dig, but there is nothing here, you had to walk 2 steps instead. I don't mind if you keep the existing rule, because it adds a little corner case to handle. But remember what happened to that laddie. \$\endgroup\$