The unnecessary and convoluted story
I am walking around manhattan, block by block and my feet have gotten tired and want to go back home.
The traffic is pretty bad, but fortunately I'm very rich and I have a helicopter on standby at the hotel. But I need them to know how much fuel to pack for the flight and for that they need to know my direct distance from the hotel. I did remember which blocks I walked and can tell them what route I took. This distance needs to be precise though, if they are too short we won't make it back, too long and I've bought fuel I can't use.
Can you write me a program to convert that into the distance they will have to travel on their flight to fetch me?
Write me a function that:
- Accepts a list or string of blocks walked relative to an arbitrary grid:
- U p, D own, L eft and R ight.
- Can be either upper or lower case - eg. if its shorter to use
- An invalid direction has undefined behaviour - eg. a direction of X can cause a failure.
- Returns a float/decimal/double that is twice the straight line distance from the point of origin.
For illustration and clarification:
My trip could have just as easily been recorded as
['l','u','l'...] but it must be recorded as Up, Down, Left, Right.