The great pirate Silver has buried a treasure on a tropical island. You
managed to find a map of the island with an X marking a spot on the island,
and a set of instructions.
Each instruction is of the form "walk A steps in the direction B".
If you start at the X and follow the instructions in the given order,
at the end you will arrive at the location where the treasure is buried.
Your evil twin has a copy of the map, and has already started to follow
the instructions. To beat him, you must find the location of the treasure
and walk straight to that place.
You will be given the set of instructions as a int[] steps and a String[]
directions.
Element i of directions corresponds to element i of steps.
Write a method that will find the location of the treasure, and
return the straight-line distance (in steps) from the place
where you start to the place where the treasure is buried.
Each direction in directions will be one of the eight basic directions on a compass.
Refer to the image below for clarification.
|