Problem Statement
No more than 10 letters are ever used to name a direction. That means that there are exactly 2048 directions. This diagram shows all of the directions in the Northeast quadrant that can be expressed in 4 or fewer letters.
N | NNNE | NNE | ENNE | NE | NENE | ENE | EENE -----------+-----------------E | | | | |
Create a class NENE that contains the method vulnerable that takes the ends of
the circular arcs as inputs, and returns the first direction counterclockwise
from East which is not protected. Return the
The ends are input as
Definition
- Class:
- NENE
- Method:
- vulnerable
- Parameters:
- String[], String[]
- Returns:
- String
- Method signature:
- String vulnerable(String[] cw, String[] ccw)
- (be sure your method is public)
Notes
- E is the last direction to check and return. See Example 4)
- the returned direction must be a legal one, so it must have no more than 10 characters
- every legal direction other than the compass points must end in either NE, SW, SE, or NW so, for example, EN or NEN would not be legal directions
- a wall protects its own endpoints.
Constraints
- cw has between 1 and 50 elements
- ccw has the same number of elements as cw
- each element of cw and ccw contains between 1 and 10 characters inclusive
- each element of cw and ccw is a legal direction
- no element of cw is equal to the corresponding element of ccw
Examples
{"E"}
{"W"}
Returns: "WWWWWWWWSW"
The one wall has an end to the east, and extends from there counterclockwise until its other end is to the west. The answer is the first legal direction counterclockwise from W.
{"E","E","SE"}
{"W","N","S"}
Returns: "SSSSSSSSSE"
The first wall is the same as in the preceding example. The second wall protects nothing new. The third wall covers everything except the section from S to SE. The answer is the first direction counterclockwise from S.
{"SSSESESESE","NE"}
{"NNE","NWNWNW"}
Returns: "NNNWNWNWNW"
{"E","WWWWWWWWSW"}
{"W","NE"}
Returns: "SAFE"
Even though there is a small gap, all the legal directions are covered.
{"EEESE","NE","SSW"}
{"SSSSSSSWSW","NW","SE"}
Returns: "SW"
{"EEEENE","WNW","SSWWSW"}
{"NNNNENEENE","WWNW","EEENE"}
Returns: "NEENE"
{"EEEENE","WNW","NEENE"}
{"NNNNENEENE","WWNW","EEENE"}
Returns: "SAFE"
{"NEENE"}
{"EEENE"}
Returns: "EEEENEEENE"
{"NW","SW"}
{"WSW","E"}
Returns: "EEEEEEEENE"
{"EEEEEEEENE","W"}
{"WWWWWWWWNW","EEEEEEEESE"}
Returns: "E"
{"W"}
{"S"}
Returns: "EEEEEEEENE"
{"SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE"}
{"WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW","WSWSWSWSSW"}
Returns: "SWSWSWSSW"
{"E","N","W","S"}
{"N","W","S","E"}
Returns: "SAFE"
{"EEEEEEEENE","W"}
{"W","EEEEEEEESE"}
Returns: "E"
{"SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE","SE"}
{"N","NW","NNW","NNNW","NNNNW","NNNNNW","NNNNNNW","NNNNNNNW","NNNNNNNNW","NNNNNNNNNW","N","NW","NNW","NNNW","NNNNW","NNNNNW","NNNNNNW","NNNNNNNW","NNNNNNNNW","NNNNNNNNNW","N","NW","NNW","NNNW","NNNNW","NNNNNW","NNNNNNW","NNNNNNNW","NNNNNNNNW","NNNNNNNNNW","N","NW","NNW","NNNW","NNNNW","NNNNNW","NNNNNNW","NNNNNNNW","NNNNNNNNW","NNNNNNNNNW","N","NW","NNW","NNNW","NNNNW","NNNNNW","NNNNNNW","NNNNNNNW","NNNNNNNNW","NNNNNNNNNW"}
Returns: "NNNNNNNWNW"