Blackbeard was an English pirate of the early 18th century. Although he was known for looting and taking ships, he commanded his vessels with the permission of their crews. There are no accounts of him ever harming or murdering his captives.
This challenge is in honor of the infamous Blackbeard and inspired by International Talk Like a Pirate Day (September 19). It is also the inverse of this challenge by Pyrrha.
The Challenge
Create a program that takes a treasure map as an input (composed of the characters listed below), and outputs it's directions.
Input
All inputs will consist of v, >, <, ^, whitespace, and a single X.
You can assume the following:
the map will never loop or cross itself
the starting arrow will always be the bottommost character in the leftmost column
there will always be a treasure (
X)
A sample input is shown below.
>>v >>>>>>v ^ v ^ v ^ v ^ v<< ^ v ^ v ^ >>>>^ >>X ^ >>^ Output
The output should be a ", "-delimited string of directions. Below is the correct output from the above map.
E2, N6, E2, S4, E4, N4, E6, S2, W2, S2, E2 A single trailing newline or space is permitted.
Examples
In: >>>>>>>>>>>>>>>v v v >>>>X Out: E15, S3, E4 In: >>>>>>v ^ v ^ >>>>X Out: N2, E6, S2, E4 In: X ^ ^ ^ Out: N3 In: >>>>>>v ^ v ^ v v >>>>>>X Out: N2, E6, S4, E6 In: X ^ ^ >^ Out: E1, N3 In: >X Out: E1 In: v<<<<< vX<<<^ >>>>^^ >>>>>^ Out: E5, N3, W5, S2, E4, N1, W3 Happy International Talk Like a Pirate Day!